2 Replies Latest reply on Oct 15, 2009 2:49 PM by tbpotter

    How to maintain state through a camel route in SMX 3.4

    tbpotter

      I am using ServiceMix 3.4.0.2 and I have a camel route (Java DSL) where I need to maintain state throughout the entire route. Can I store state in non-static fields in my RouteBuilder class? Is this threadsafe in SMX 3.4? Is each request processed by its own instance of RouteBuilder?

       

      Thanks,

      Tim

        • 1. Re: How to maintain state through a camel route in SMX 3.4
          davsclaus

          You can store state on the Camel Exchange as property. They will there for the entire lifecycle for that particular exchange while its being routed in Camel.

           

          The RouteBuilder is used to create the route model to the actual runtime route and as such there is only one instance of it.

           

          You can access the properties on the Exchange from a Camel processor

          public void process(Exchange exchange) throws Exception {
             String foo = (String) exchange.getProperty("myFoo");
             ...
             exchange.setProperty("myFoo", updatedValue);
          }
          

           

          • 2. Re: How to maintain state through a camel route in SMX 3.4
            tbpotter

            Thanks for your quick reply!!! I'll implement it the way you suggested.