Question

I am very new to Apache Camel. We have a requirement of handling multiple dynamic routes life-cycle together.

Say, there is one route A (static) which, on receiving a message spawns another route B dynamically (the endpoints of B is defined in the message itself, not known in advance). There are different routes created for different messages.

Our problem is, there is a class X where from we want to suspend A and resume B and from another class Y just opposite. This switching is not working. In X, before A is suspended fully, the JVM tries to execute resume operation on B, and it seems like the threads are blocked.

It is only my guess that it is a synchronization issue. How to address this kind of problem?

RouteManager.deactivateRoute(ROUTE_A_ID);  //it creates a thread to suspend route as mentioned in Camel's documentation

RouteManager.activateRoute(ROUTE_B_ID);  //it adds (when B is new) or resumes

My log shows no exception, only either of two things happening,

  1. "Waiting as there are still 2 inflight and pending exchanges to complete, timeout in 300 seconds." - this message continues
  2. Nothing is printed, but B is not working (no log, nothing)
Was it helpful?

Solution 2

However, it seems to be resolved. Thanks Petter for your help. I am using ControlBus for the switching. But while using it, routes were not getting resumed by

producerTemplate.sendBody("controlbus:route?routeId=" + routeId + "&action=resume", null);

Found that we need to add the below snippet too while resuming (dont know if this is a right way to do)

producerTemplate.sendBody("controlbus:route?routeId=" + routeId + "&action=resume", null);
camelContext().getRoute(routeId).getConsumer().start();

Otherwise it had two problems,

  1. Resume command was not working using ControlBus mechanism, though as per the camel log, it said that ControlBus has successfully resumed route. (but adding new file to consumer endpoint make no effect on route)
  2. Camel was ignoring previous files too. Say, there are more than one file when route is started, then it was only picking up the first file, then goes suspended and then (when resume invoked) got silent.

OTHER TIPS

I'm not really sure how and when you try to do this "switch". However, there is an EIP mechanism for this that you might prefer.

It's called ControlBus and you can send commands to alter the lifecycle of routes. It has an "async" option, so that the current message (as it's inflight) won't disturb the shutdown of the route itself.

from("seda:foobar")
.routeId("myRoute")
.setBody().constant("${camelContext.stopRoute('myRoute')}")
.to("controlbus:language:simple?async=true")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top