apache camel - onCompletion handler with route scope fires in the middle of route -


i have issue camel 2.19.1. , oncompletion handlers route scope. runtime java 8, karaf 4.0.9. camel context built blueprint.

i have defined 3 routes oncompletion handler each:

<oncompletion mode="beforeconsumer" parallelprocessing="false" oncompleteonly="true" useoriginalmessage="false">     <log message="<route_name> success." logginglevel="info" logname="policy-repository-adapter" /> </oncompletion> 

the 3 routes call each other via direct endpoint so:

pra-soap-endpoint -> direct:xacml-policy-query -> direct:send-to-pas-endpoint 

the top-level route pra-soap-endpoint looks (pseudo code, obviously):

route pra-soap-endpoint   process   log "route checkpoint 1"   direct:xacml-policy-query   log "route checkpoint 2"   process end route 

the log output top-level route , oncompletion handlers looks this:

route checkpoint 1 send-to-pas-endpoint success. xacml-policy-query success. pra-soap-endpoint success. route checkpoint 2 send-to-pas-endpoint success. xacml-policy-query success. pra-soap-endpoint success. send-to-pas-endpoint success. xacml-policy-query success. pra-soap-endpoint success. 

note oncompletion handlers fired multiple times. on top of this, oncompletion handler of top-level route fired before route finishes (log statement pra-soap-endpoint success. before log statement route checkpoint 2).

what expected this:

route checkpoint 1 send-to-pas-endpoint success. xacml-policy-query success. route checkpoint 2 pra-soap-endpoint success. 

is bug in camel or misconception on end how oncompletion handlers work?

this behaviour correct. specified mode="beforeconsumer" on oncompletion definition, , changes behaviour of camel (since 2.14).

from the docs:

from camel 2.14: oncompletion has been modified support running completion task in either synchronous or asynchronous mode (using thread pool) , whether run before or after route consumer done. reason give more flexibility. example specify run synchronous , before route consumer done, allows modify exchange before consumer writes response callee. can use example add customer headers, or send log log response message, etc.

again, in own section:

oncompletion supports 2 modes
afterconsumer - default mode runs after consumer done.
beforeconsumer - runs before consumer done, , before consumer writes response callee.
afterconsumer mode default mode same behavior in older camel releases.
new beforeconsumer mode used run oncompletion before consumer writes response callee (if in inout mode). allows oncompletion modify exchange, such adding special headers, or log exchange response logger etc.


as solution, either use afterconsumer mode or set pattern inonly.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -