- I am using apache camel to receive all messages from the queue. But I need to mention sleep time of thread to run the camel context.
- Now the problem is it consumes only some messages ie. within the sleep time specified.
- If I increase the sleep time then it will route all the messages, but it waits until the completion of sleep time to terminate the program.
- What I need is, the camel should route all the messages in the queue and then it should terminate immediately.
Is there any way to run the camel without specifying thread sleep time using java DSL?
Sample Code :
import javax.jms.ConnectionFactory;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.camel.impl.DefaultCamelContext;
public class SplitJson {
public static void main(String[] args) {
try {
CamelContext context = new DefaultCamelContext();
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "admin",
ActiveMQConnection.DEFAULT_BROKER_URL);
context.addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
context.addRoutes(new RouteBuilder() {
public void configure() {
from("test-jms:queue:testMQDestination")
.choice()
.when().jsonpath("$.[?(@.Status == 'YetToStart')]")
.to("test-jms:queue:YetToStart")
.when().jsonpath("$.[?(@.Status == 'Started')]]")
.to("test-jms:queue:Started")
.when().jsonpath("$.[?(@.Status == 'Completed')]]")
.to("test-jms:queue:Completed")
.otherwise()
.to("test-jms:queue:Others")
.end();
}
});
context.start();
Thread.sleep(10000);
context.stop();
System.out.println("Done");
} catch (Exception e) {
e.printStackTrace();
}
}
}