I just had a very similar situation, which I got round by using a
ProducerTemplate to call the second route. So instead of the inOnly() in
route A, you would have a Processor which invokes route B synchronously,
which will leave the Exchange in route A unaltered. For example:
.transform(constant("A-BODY"))
.process(exchange -> template.sendBody("seda:B", exchange.getIn().getBody()))
.log("MyHeader is ${in.header.MyHeader}")
which produces the following output:
21:40:35.673 [Camel (camel-1) thread #0 - seda://A] INFO route1 - Hello
From A
21:40:35.676 [Camel (camel-1) thread #1 - seda://B] INFO route2 - Hello
From B
21:40:35.676 [Camel (camel-1) thread #1 - seda://B] INFO route2 - Ready
from B
21:40:35.676 [Camel (camel-1) thread #0 - seda://A] INFO route1 -
MyHeader is A-HEADER
21:40:35.677 [Camel (camel-1) thread #0 - seda://A] INFO route1 - Body
is A-BODY
Happy for someone to point out a better way, but this worked for me.
-- ctg
On 9/01/2017 12:48 p.m., sim085 wrote:
Hello,
I have a route "A" which calls a route "B", route "B" adds some headers,
removes some others, changes the body, etc. Is there a way how I can call
route "B" from route "A", wait for route "B" to finish and once route "B"
returns, route "A" will be in the same state as before calling route "B"
(i.e. - same headers, same body)?
I tried using the SEDA component with the "waitForTaskToComplete" set to
"Always" but this does not seem to work, i.e. - if I use
InOnly("seda:B?waitForTaskToComplete=Always") then this works as if calling
the SEDA component with inOut(...).
For example:
[code]
from("seda:A")
.log("Hello From A")
.setHeader("MyHeader", constant("A-HEADER"))
.transform(constant("A-BODY"))
.inOnly("seda:B?waitForTaskToComplete=Always")
.log("MyHeader is ${in.header.MyHeader}")
.log("Body is ${body}")
;
from("seda:B")
.log("Hello From B")
.setHeader("MyHeader", constant("B-HEADER"))
.transform(constant("B-BODY"))
.log("Ready from B")
;
[/code]
Will Print:
[(camel-1) thread #0 - seda://A] route2 INFO Hello
>From A
[(camel-1) thread #1 - seda://B] route3 INFO Hello
>From B
[(camel-1) thread #1 - seda://B] route3 INFO Ready
from B
[(camel-1) thread #0 - seda://A] route2 INFO
MyHeader is B-HEADER
[(camel-1) thread #0 - seda://A] route2 INFO Body
is B-BODY
I was under the impression that calling seda:B with InOnly would force the
component not to return however it seems that waitForTaskToComplete=Always
makes it work like InOut rather than just wait for the task to complete.
Is there a way how I can achieve the above? i.e. - call a route, wait for
this to finish, but message from the caller route (in my case "A") remains
the same as before calling the second route.
--
View this message in context:
http://camel.465427.n5.nabble.com/How-to-call-a-route-wait-to-finish-and-ignore-any-changes-when-this-returns-tp5792288.html
Sent from the Camel - Users mailing list archive at Nabble.com.