4 Replies Latest reply on Nov 20, 2014 11:48 AM by Akram KAMMOUN

    Switchyard + JMS + Camel

    Akram KAMMOUN Newbie

      Hi,

      I am currently working on a project using the fuse service works (switchyard, ....). The issue that i want to define a JMS bean in beans.xml and then use it in a camel routes (routes.xml). I tried many ways but without suceess.

      In beans.xml:

          <bean id="jms_activemq" class="org.apache.camel.component.jms.JmsComponent">

              <property name="ConnectionFactory">

                  <bean class="org.apache.activemq.ActiveMQConnectionFactory">

                      <property name="brokerURL" value="vm://localhost" />

                  </bean>

              </property>

          </bean>


      In routes.xml:

      <routes xmlns="http://camel.apache.org/schema/spring">

          <route>

              <from uri="switchyard://ServiceTest"/>

              <to uri="jms_activemq:queue:incomingOrders"/>

          </route>

      </routes>

       

      Any suggestions would be grateful.

       

      Thank you.

        • 1. Re: Switchyard + JMS + Camel
          Keith Babo Master

          You should be able to achieve this be creating a CDI bean class which extends JmsComponent and uses @Named("jms_activemq").  Or you could have a class with an @Produces @Named("jms_activemq") method which returns a configured instance of JmsComponent.

          1 of 1 people found this helpful
          • 2. Re: Switchyard + JMS + Camel
            Akram KAMMOUN Newbie

            Thank you for your prompt replay. I have created a class "ActiveMQComponentFactory" (as follows) and I have added this route "<to uri="activemqComp://testQueue" />" to my camel script. I had this error: No component found with scheme: activemqComp.

             

                public class ActiveMQComponentFactory extends JmsComponent{ 

                     

                    @Produces @Named ("activemqComp") 

                    public JmsComponent createActiveMQComponent() { 

                    JmsComponent ac = new ActiveMQComponent(); 

                   

                    try {

                        InitialContext ic = new InitialContext();

                            ConnectionFactory cf = (ConnectionFactory) ic.lookup("ConnectionFactory");

                       

                            ac.setConnectionFactory(cf);

                        } catch (NamingException e) {

                            // TODO Auto-generated catch block

                            e.printStackTrace();

                        }

                    return ac; 

                    } 

                  

                }

             

            I tried to use hornetq instead of activemq by creating the following class and the result was fine and everything was ok.

             

                public class HornetQComponent extends JmsComponent {

               

                    @Produces @Named ("hornetqComp") 

                    public JmsComponent createHornetMQComponent() { 

             

                        JmsComponent hq = new HornetQComponent();

                        InitialContext ic;

                   

                        try {

                            ic = new InitialContext();

                            ConnectionFactory cf = (ConnectionFactory) ic.lookup("ConnectionFactory");

                       

                            hq.setConnectionFactory(cf);

                        } catch (NamingException e) {

                            // TODO Auto-generated catch block

                            e.printStackTrace();

                        }

                   

                    return hq; 

                    } 

                }

             

             

            I am wondering why hornetq runs well and activemq does not? It seems that JBoss eap 6.1 does ont recognise ActiveMQ.

            • 3. Re: Switchyard + JMS + Camel
              Keith Babo Master

              ActiveMQ jars are not present in EAP / FSW by default.  My guess would be that CDI discovery is reaching your @Produces method, encountering a CNF exception and swallowing it.

              • 4. Re: Switchyard + JMS + Camel
                Akram KAMMOUN Newbie

                Thank you for the explanations. The problem is solved.