3 Replies Latest reply on Oct 6, 2010 12:16 AM by davsclaus

    stopping a route within processor

    guest

      I was wondering what would be the best way to stop a route within a processor? My route is something like this:

       

           

       

      I'd like to be able to stop the route from going on depending on some logic defined within the MyProcessor bean.  What's the best way to do this rather than throwing an exception?

        • 1. Re: stopping a route within processor
          njiang

          You can do it from Camel 2.4.0. like this

             <route id="myRoute">
               <from uri="timer://PullTimer?fixedRate=true&amp;period=1000"></from>
               <process ref="MyProcessor"></process>
               ... <!-- more stuff here-->
               ...
             </route>
          

           

           

                public void process(Exchange exchange) throws Exception {
                              
                              // force stopping this route while we are routing an Exchange
                              // requires two steps:
                              // 1) unregister from the inflight registry (in Camel 2.5.0)
                              // 2) stop the route
                              getContext().getInflightRepository().remove(exchange);
                              getContext().stopRoute("myRoute");
                  }
           

           

            You can find more information about it in Camel in Action Chapter 13.

          • 2. Re: stopping a route within processor
            guest

            Looks like the suggested fix actually stopped the route from kicking off totally.  I'd like for it to just stop for that one instance.

            • 3. Re: stopping a route within processor
              davsclaus

              There is a <stop/> in the DSL you can use.

               

              Or you can set a header on the current Exchange. Exchange.STOP (I think thats key key) with the value Boolean.TRUE.