6 Replies Latest reply on Apr 10, 2015 3:16 AM by stepha.dereppe

    Active MQ with Camel on Fuse - How to?

    stepha.dereppe

      Hello,

       

      I'm tring to play around with Active MQ and Camel on a local Fuse instance.

       

      Here is what I've done.

       

      1/ Create a child container that run the mq-default profile (the broker)

       

      2/ Create a new Camel Project with the following camelContext (I started from a given maven archetype):

       

      <beans xmlns="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:amq="http://activemq.apache.org/schema/core"
             xsi:schemaLocation="
             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
             http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
             http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
      
      
       <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
          <property name="brokerURL" value="discovery:(fabric:default)"/>
        </bean>  
      
      <camelContext xmlns="http://camel.apache.org/schema/spring">
        <route id="fileToMessage">
          <from uri="file:C:\\CamelTest\\In"/>
          <to uri="activemq:personnel.records"/>
        </route>
        <route id="consumeMessageToFile">
          <from uri="activemq:personnel.records"/>
          <choice>
            <when>
              <xpath>/person/city = 'London'</xpath>
              <to uri="file:C:\\CamelTest\\Out\\messages\\uk"/>
            </when>
            <otherwise>
              <to uri="file:C:\\CamelTest\\Out\\messages\\others"/>
            </otherwise>
          </choice>
        </route>
      </camelContext>
      </beans>
      

       

      I create a profile with this bundle and assign it to another child container.

       

      I receive this error

       

      Failed delivery for (MessageId: ID-PORT-STEDE-50609-1428487890125-0-4947 on ExchangeId: ID-PORT-STEDE-50609-1428487890125-0-4948).
      Exhausted after delivery attempt: 1 caught: org.springframework.jms.IllegalStateException: javax.jms.JMSException: Stopped.; nested exception is javax.jms.IllegalStateException: javax.jms.JMSException: Stopped.
      

       

      Can someone help me? I don't know what I do wrong...

       

      Thanks.

       

      Stéphane

        • 1. Re: Active MQ with Camel on Fuse - How to?
          bharadwaj

          Hello Steph,

           

          you can not directly define broker URL for activemqComponent . Please follow below config snippet.

           

           

           

          <bean id="jmsConnectionFactory"

           

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

             <property name="brokerURL" value="tcp://localhost:61616" />

          </bean>

           

          <bean id="pooledConnectionFactory"

             class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start" destroy-method="stop">

             <property name="maxConnections" value="8" />

             <property name="connectionFactory" ref="jmsConnectionFactory" />

          </bean>

           

          <bean id="jmsConfig"

             class="org.apache.camel.component.jms.JmsConfiguration">

             <property name="connectionFactory" ref="pooledConnectionFactory"/>

             <property name="concurrentConsumers" value="10"/>

          </bean>

           

          <bean id="activemq"

              class="org.apache.activemq.camel.component.ActiveMQComponent">

              <property name="configuration" ref="jmsConfig"/>

           

              <!-- if we are using transacted then enable CACHE_CONSUMER (if not using XA) to run faster

                   see more details at: http://camel.apache.org/jms

              <property name="transacted" value="true"/>

              <property name="cacheLevelName" value="CACHE_CONSUMER" />

              -->

          </bean>

          • 2. Re: Active MQ with Camel on Fuse - How to?
            stepha.dereppe

            Hello,

             

            Thanks for the reply. it seems that you snippet helped !

             

            But now I get the following exception :

             

            Failed delivery for (MessageId: ID-PORT-STEDE-53147-1428495900009-0-1 on ExchangeId: ID-PORT-STEDE-53147-1428495900009-0-2). Exhausted after delivery attempt: 1 caught: org.springframework.jms.UncategorizedJmsException: Uncategorized exception occured during JMS processing; nested exception is javax.jms.JMSException: Error while attempting to add new Connection to the pool; nested exception is javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused: connect

             

            On the broker container, I've noticed this in the log :

             

             

            Could that be the problem?

             

            I don't have change any configuration...

            Any idea?

            • 3. Re: Active MQ with Camel on Fuse - How to?
              bharadwaj

              Please provide usename and password same as Jboss fuse ESB username and password  /etc/ user.properties enable username,password and role.

               

              <bean id="jmsConnectionFactory"

               

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

                 <property name="brokerURL" value="tcp://localhost:61616" />

              <property name="userName" value="admin" />

              <property name="password" value="admin" />

               

              </bean

              1 of 1 people found this helpful
              • 4. Re: Active MQ with Camel on Fuse - How to?
                stepha.dereppe

                With this configuration i got the following exception;

                 

                Could not refresh JMS Connection for destination 'personnel.records' - retrying in 5000 ms. Cause: Error while attempting to add new Connection to the pool; nested exception is javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused: connect

                As I saw the following message in the broker's side log :

                 

                apache.activemq.transport.TransportServerThreadSupport : Listening for connections at: tcp://PORT-STEDE:56587

                If change the port in the ActiveMQConnectionFactory bean property to 56587 and it worked !

                 

                Is there a way to force the broker using the port 61616 ? It seems that the port change at every restart of the server ==> I have to change my bean definition each time. Which is not cool :-)

                 

                Thanks for you help !

                • 5. Re: Active MQ with Camel on Fuse - How to?
                  bharadwaj

                  Instead of going to code and changing every time, read broker url form external properties:

                   

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

                    <property name="brokerURL" value="${broker_url}" />

                    <property name="userName" value="${activemq_uname}"></property>

                    <property name="password" value="${activemq_password}"></property>

                    </bean>

                  • 6. Re: Active MQ with Camel on Fuse - How to?
                    stepha.dereppe

                    The problem is not giving the port number of the broker in the client side.

                     

                    The problem is that the port number of the broker change at every startup . I don't know why and how to fix this (I thought that the default was 61616).

                     

                    I workaround this problem with this

                    <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
                    <property name="brokerURL" value="discovery:(fabric:default)" />
                    <property name="userName" value="admin"/>

                      <property name="password" value="admin"/>

                    </bean>

                     

                    It seems to magically discover the broker port number. Which is great for a camel route that run inside the Fuse container... But it won't work with a external client.

                     

                    Any idea why the broker's port number is not set to the default?

                     

                    Thanks for your help