4 Replies Latest reply on Aug 2, 2012 9:15 AM by edevera

    Camel RouteBuilder onException statement

    edevera

      Does anybody know if the onException construct for the RouteBuilder is available for Switchyard Camel RouteBuilder based Services? I would need to use it in order to leverage the functionality of the retry mechanism. I have something like this in my route builder's configuration method:

       

       

      onException(MyException.class)
                      .maximumRedeliveries(numberOfTimes);
      

       

      But it doesnt seem to work at all even if I see the exception ocurring in the log.

       

      Is this Camel feature supported?

        • 1. Re: Camel RouteBuilder onException statement
          splatch

          Hey Eduardo,

          Because current support for Camel in Switchyard implementation.camel is limited to route elements you have to put onException definition inside route element:

           

           

          from("switchyard://service")
              .onException(...)
              .end()
          .to("switchyard://reference")
          
          • 2. Re: Camel RouteBuilder onException statement
            edevera

            So, if I add the onException right after the from call, are all the services candidates of being called that throw the specified exception treated? That would allow me to only define it once which is what I was considering by doing what I have asked.

             

            Thanks!

            • 3. Re: Camel RouteBuilder onException statement
              splatch

              You can add multiple onException definitions inside route - just like you do inside route builder/camel context. The main difference is scope of onException closure. The onException part is called only if you have matching exception thrown somewhere in route. The normal (correct) flow skips onException execution.

              • 4. Re: Camel RouteBuilder onException statement
                edevera

                Hi Lukasz,

                 

                I have managed to have global exception handling defined once only by doing this:

                 

                 

                public void configure() {
                
                onException(MyException.class)
                   .maximumRedeliveries(3)
                .to(myDeadLetterEndpoint);
                
                  from("switchyard:...")...
                
                }
                

                 

                Which is what I originally intended and works like a charm.

                 

                Thanks a lot for your help!