Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-19422

camel-core using a thread to stop a route from a route

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Invalid
    • 3.20.3
    • None
    • came-core
    • Unknown

    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();
          }
      } 
      

      **

       

      Attachments

        1. log.txt
          16 kB
          Shashank Mugatkar

        Activity

          People

            Unassigned Unassigned
            shashank_09 Shashank Mugatkar
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: