3 Replies Latest reply on Nov 25, 2011 7:29 AM by jamie archibald

    Dynamic Router + Bean + ActiveMQ

    jamie archibald Apprentice

      Having a weird issue with a DynamicRouter which is wired to send the exchange to a bean which is defined in my spring context. The input body of the exchange determines the method name on the bean to invoke. The problem I am having is that the client will receive the return (e.g. String) from the route if I use a "direct" endpoint as the consumer on my route. If I change from "direct" to "activemq:queue" camel repeatedly keeps invoking the MyBean classes method and I get the following showing up in the debug log:

       

       

      [d #0 - JmsConsumer[route1] BeanProcessor                  DEBUG Setting bean invocation result on the OUT message: []

      [d #0 - JmsConsumer[route1] BeanProcessor                  DEBUG Setting bean invocation result on the OUT message: bean:myBean?method=foo

       

       

      // this doesnt work in ActiveMQ, but does with with direct

      ProducerTemplate tmpl = ..;

      String s = tmpl.requestBody("activemq:queue:request", "foo", String.class);

       

       

       

       

       

      public class MyBean {

       

         public void foo() {

            return "foo";

        }

       

         public void bar() {

            return "bar";

         }

      }

       

      public class MyRouter extends RouteBuilder {

       

         public void configure() {

             from("activemq:queue:request")    // this fails with activemq, but works if changed to use direct

             .dynamicRouter(bean(new MyDynamicRouter());

          

         }

      }

       

      public class MyDynamicRouter {

          public String route(Object methodName) {

              return "bean:myBean?method=" + methodName;

          }

      }