title: Receive messages from activemq using apache camel java DSL
body: <ul>
  <li>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.</li>
  <li>Now the problem is it consumes only some messages ie. within the
  sleep time specified.</li>
  <li>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.</li>
  <li>What I need is, the camel should route all the messages in the queue
  and then it should terminate immediately.</li>
  </ul>
  
  <p>Is there any way to run the camel without specifying thread sleep time using java DSL?</p>
  
  <p><strong>Sample Code :</strong></p>
  
  <pre><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();
          }
  
      }
  
  }
  </code></pre>