Reputation: 2049
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,
Upvotes: 1
Views: 1609
Reputation: 2049
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,
Upvotes: 0
Reputation: 22279
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")
Upvotes: 1