8 Replies Latest reply: Oct 17, 2013 4:37 PM by Keith Babo RSS

How can i use switchyard camel with activemq?

alex liu Newbie

I get confused in  switchyard camel ,Mq in default is hornetQ,But I am interesting in how to use activemq with camel

  • 1. Re: How can i use switchyard camel with activemq?
    Daniel Bevenius Master

    Hi,

     

    I've not had time to try this out yet, but in theory you should be able to use a CDI to specify a method that creates an ActiveMQComponent:

     

    import javax.enterprise.context.ApplicationScoped;
    import javax.enterprise.inject.Produces;
    import javax.inject.Named;
    import org.apache.activemq.ActiveMQConnectionFactory;
    import org.apache.activemq.camel.component.ActiveMQComponent;
     
    @ApplicationScoped
    public class ActiveMQComponentFactory {
        
        @Produces @Named ("activemq")
        public ActiveMQComponent createActiveMQComponent() {
            final ActiveMQComponent ac = new ActiveMQComponent();
            final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
            factory.setBrokerURL("vm://localhost?broker.persistent=false&broker.useJmx=false");
            ac.setConnectionFactory(factory);
            return ac;
        }
     
    }
    

     

    In SwitchYard CDI components are available to Camel's registry so you can specify 'activemq' in the uri as shown below:

    <camel:binding.camel configURI="activemq://TestQueue"/>
    

     

     

    Regards,

     

    /Daniel

  • 2. Re: How can i use switchyard camel with activemq?
    Keith Babo Master

    In addition to what Dan posted, you will also need to add the activemq camel component and dependencies as modules in the AS7 distribution.

     

    I would be interested in hearing about how this turns out, so please post back with questions/results if you decide to try it yourself.  If not, we'll probably get around crafting an example sooner or later.

  • 3. Re: How can i use switchyard camel with activemq?
    Daniel Bevenius Master

    We've add a jira for this which you can find here:

    https://issues.jboss.org/browse/SWITCHYARD-747

  • 4. Re: How can i use switchyard camel with activemq?
    alex liu Newbie

    After trying to deloy activemq component using switchyard CDI, i got failed.

    1.I put the ActiveMQComponentFactory.java to project switchyard-quickstart-camel-service,

    2.write a sample route class:

    public interface MyTestDSL {
    public void sendMessage(String input);
    }

         @Route(MyTestDSL.class)
    public class MyTestDSLBuilder extends RouteBuilder{


    @Override
    public void configure() {
            from("switchyard://MyTestDSL")
                .log("Message received in Java DSL Route")
                .log("${body}")
                .split(body(String.class).tokenize("\n"))
                .filter(body(String.class).startsWith("sally:"))
                .to("activemq://TestQueue");
        }

    }

     

    3.generate jar using maven,start jboss as7,then deploy this jar

     

    4.finally,i got those errors bellow:

     

    10:41:09,751 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC00001: Failed to start service jboss.deployment.unit."switchyard-quickstart-camel-service.jar".SwitchYardService: org.jboss.msc.service.StartException in service jboss.deployment.unit."switchyard-quickstart-camel-service.jar".SwitchYardService: org.switchyard.exception.SwitchYardException: Failed to create route route2 at: >>> Split[{tokenize(bodyAs[java.lang.String],
    )} -> [Filter[{bodyAs[java.lang.String] startsWith sally:} -> [To[activemq://alexQueue]]]]] <<< in route: Route[[From[switchyard://MyTestDSL?namespace=urn%3Aswitchyar... because of Failed to resolve endpoint: activemq://alexQueue due to: No component found with scheme: activemq

     

    absolutly,component  "activemq" is failed to register.

  • 5. Re: How can i use switchyard camel with activemq?
    Keith Babo Master

    This is because the ActiveMQ Camel component has not been installed as a module in your AS7 instance.  Dan is cooking up a quickstart that will likely help you a lot.  My suggestion would be to wait a bit on the ActiveMQ front and take a look at what he produces.

  • 6. Re: How can i use switchyard camel with activemq?
    Daniel Bevenius Master

    Hi,

     

    attached you'll find a zip file containing a AS7 module for activemq-camel which can be unzipped to your AS7 installation:

     

     unzip camel-activemq-module.zip -d /path/to/as7/home
    

     

    We've added a quickstart but we have not pushed it upstream yet as we need to descide where to put the Camel modules first. But if might be helpful to have as a reference and perhaps start but verifying that you can get it working and then make changes to implement your specific use case. The quickstart uses a XML DSL as opposed to the JavaDSL that your example is using, but it should be able to find the ActiveMQComponent now.

     

    I'll post back when the quickstart and the modules are available upstream.

     

    Lets us know if you run into any issues.

     

    Regard,

     

    /Daniel

  • 7. Re: How can i use switchyard camel with activemq?
    Charles Moulliard Newbie

    Should be interesting to move this example to the quickstart github repo of jboss-switchyard repository