Details
Description
I have multiple messages which should be sent to a MQ 'foo'. After sending a message from 'route-1', the program should wait for a reply on MQ 'bar'. Only after getting a reply on queue 'bar', the next message should be sent.
How can I stop a route from a route :: Apache Camel
I have followed the steps given in the documentation. All the messages are getting routed and then the route is getting suspended.
input.txt
{{}}
msg1,msg2,msg3,msg4,msg5
beans.xml
<camelContext id="orc-1" xmlns="http://camel.apache.org/schema/spring"> <route id="route-1"> <from uri="file://D://camelInput?fileName=input.txt" /> <split> <tokenize token="," /> <log message="${body}" /> <to uri="jms:queue:foo" /> <process ref="postProcessor" /> </split> </route> <route id="route-2"> <from uri="jms:queue:bar" /> <!--restart route-1--> </route> </camelContext>
PostProcessor.java
public class PostProcessor implements Processor { Thread stop; @Override public void process(Exchange exchange) throws Exception { // stop this route using a thread that will stop // this route gracefully while we are still running if (stop == null) { stop = new Thread() { @Override public void run() { try { exchange.getContext().getRouteController().suspendRoute("route-1"); } catch (Exception e) { // ignore } } }; } // start the thread that stops this route stop.start(); } }
**