I have two routes, an ‘outer route’ that is called from ‘outside’ and an
‘inner route’ that processes some sub tasks. Both routes have individual
/onCompletions /(with route scope).

Now I am facing the problem, that the /onCompletion /of the ‘inner route’ is
only called when the ‘outer route’ finishes. Furthermore the body of the
inner /onCompletion /is the body of the outer result.
This behavior only occurs when I use direct to communicate.

I also tried to use the mode /BeforeConsumer /for the inner route but the
the /onCompletion /of the inner route is called twice.

Below the example code and log:
// *******************************
// Outer route
// *******************************
from(direct:outerStart).routeId("OuterRoute")
.onCompletion().to("log:outerOnCompletion?showAll=true").end()
.inOnly(direct:innerStart).setBody().constant("I am
back").to("log:IamDone");
// *******************************
// Inner route
// *******************************
from(direct:innerStart).routeId("InnerRoute")
.onCompletion().to("log:innerOnCompletion?showAll=true").end()
.setBody().constant("Do the inner route work")
.to("log:finishedInnerWork?showAll=true");

The resulting log looks like this…
[finishedInnerWork] - Exchange[Id: ..., ExchangePattern: InOut, Properties:
..., Headers: ..., BodyType: String, Body: Do the inner route work, Out:
null: ]
[IamDone] - Exchange[ExchangePattern: InOut, BodyType: String, Body: I am
back]
[innerOnCompletion] - Exchange[Id: ..., ExchangePattern: InOut, Properties:
..., Headers: ..., BodyType: String, Body: I am back, Out: null: ]
[outerOnCompletion] - Exchange[Id: ..., ExchangePattern: InOnly, Properties:
..., Headers: ..., BodyType: String, Body: I am back, Out: null: ]

If I set the mode of the inner /onCompletion/ to /BeforeConsumer/ the result
is the following:

[finishedInnerWork] - Exchange[Id: ..., ExchangePattern: InOut, Properties:
..., Headers: ..., BodyType: String, Body: Do the inner route work, Out:
null: ]
[innerOnCompletion] - Exchange[Id: ..., ExchangePattern: InOut, Properties:
..., Headers: ..., BodyType: String, Body: Do the inner route work, Out:
null: ]
[IamDone] - Exchange[ExchangePattern: InOut, BodyType: String, Body: I am
back]
[innerOnCompletion] - Exchange[Id: ..., ExchangePattern: InOut, Properties:
..., Headers: ..., BodyType: String, Body: I am back, OutHeaders: ...,
OutBodyType: String, OutBody: I am back]
[outerOnCompletion] - Exchange[Id: ..., ExchangePattern: InOnly, Properties:
..., Headers: ..., BodyType: String, Body: I am back, Out: null: ]

I expected the inner /onCompletion /to be called when the inner route
finished. But no it is tied with the outer route?

Regards,
Thomas




--
View this message in context: 
http://camel.465427.n5.nabble.com/Unexpected-onCompletion-behavior-when-using-direct-tp5777567.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to