6 Replies Latest reply on Aug 12, 2015 1:56 AM by rm0han

    JBoss HornetQ setup and Spring

    rm0han

      I am changing my exisiting Spring JMS configuration to use HornetQ in Jboss so that I can execute Arquillian tests.

       

      My HornetQ configuration is this.

       

      <?xml version="1.0" encoding="UTF-8"?>

      <messaging-deployment xmlns="urn:jboss:messaging-deployment:1.0">

        <hornetq-server>

          <connection-factory name="ConnectionFactory">

              <connectors>

                  <connector-ref connector-name="in-vm"/>

              </connectors>

              <entries>

                  <entry name="ConnectionFactory"/>

              </entries>

              <consumer-window-size>0</consumer-window-size>

              <retry-interval>1000</retry-interval>

              <retry-interval-multiplier>1.5</retry-interval-multiplier>

              <max-retry-interval>60000</max-retry-interval>

              <reconnect-attempts>1000</reconnect-attempts>

          </connection-factory>

        <jms-destinations>

        <jms-queue name="test">

        <entry name="queue/putplan" />

        <entry name="java:jboss/exported/jms/queue/test" />

        </jms-queue>

        <jms-queue name="test4

        ">

        <entry name="devicePermissionsCheckReqQueue" />

        <entry name="java:jboss/exported/jms/queue/test4" />

        </jms-queue>

        </jms-destinations>

        </hornetq-server>

      </messaging-deployment>

       

      My Spring conf. is this. I have added comments to show problems faced.

       

           <bean id="jmsQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">

           <property name="jndiName" value="java:/jboss/exported/jms/ConnectionFactory" />

           <property name="lookupOnStartup" value="false"/>

           <property name="proxyInterface" value="javax.jms.ConnectionFactory"/>

        </bean>

       

        <!-- I want to inject this template. Doesn't throw errors -->

        <bean id="regResponseJmsTemplate" class="org.springframework.jms.core.JmsTemplate">

        <constructor-arg name="connectionFactory" ref="jmsQueueConnectionFactory"></constructor-arg>

        </bean>

       

        <!-- How do I refer a queue here from the HornetQ configuration ? This doesn't seem to be right. My HornetQ is embedded in JBoss and my EAR is deployed-->

        <!-- Throws errors. EAR with Arquillian tests are deployed in JBoss -->

        <bean id="defaultDestination" class="org.hornetq.jms.client.HornetQQueue">

              <constructor-arg index="0" value="accountPermissiondestinationQueue"/>

          </bean>

       

      <bean id="Listener"

        class="org.springframework.jms.listener.DefaultMessageListenerContainer">

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

        <property name="destination" ref="accountPermissiondestinationQueue" />

        <property name="messageListener" ref="permissionListener" />

        </bean>

       

      Can anyone point out the right approach ?

       

      Thanks,

      Mohan

        • 1. Re: JBoss HornetQ setup and Spring
          jbertram

          It might help for you to look at the Spring integration example that ships with HornetQ.  It demonstrates how to creates beans for a connection factory and a queue (among other things).  In short, you can directly instantiate connection factories and queues or you can look them up in JNDI if you want as well.

          • 2. Re: JBoss HornetQ setup and Spring
            rm0han

            I did look at that simple example(GC: examples / jms / spring-integration / server0 / spring-jms-beans.xml - GrepCode Source).

            But it didn't help me much.

            I need to configure a jmstemplate and a DefaultMessageListenerContainer

             

            I get this -  javax.naming.NameNotFoundException: queue/test4 -- service jboss.naming.context.java.queue.test4

             

            <?xml version="1.0" encoding="UTF-8"?>

            <messaging-deployment xmlns="urn:jboss:messaging-deployment:1.0">

              <hornetq-server>

                <connection-factory name="ConnectionFactory">

                    <connectors>

                        <connector-ref connector-name="in-vm"/>

                    </connectors>

                    <entries>

                                        <entry name="java:/ConnectionFactory"/>

                    </entries>

                    <consumer-window-size>0</consumer-window-size>

                    <retry-interval>1000</retry-interval>

                    <retry-interval-multiplier>1.5</retry-interval-multiplier>

                    <max-retry-interval>60000</max-retry-interval>

                    <reconnect-attempts>1000</reconnect-attempts>

                </connection-factory>

             

             

                <!--the queue used by the example-->

                <queue name="test4">

                    <entry name="queue/test4"/>

                    <entry name="java:jboss/exported/jms/queue/test4"/>

                </queue>

              </hornetq-server>

            </messaging-deployment>

             

            Spring :

             

            <bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">

              <property name="jndiName">

              <value>ConnectionFactory</value>

              </property>

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

              </bean>

              <bean id="myBrokerSendDestination" class="org.springframework.jndi.JndiObjectFactoryBean">

                   <property name="jndiName">

                       <value>queue/test4</value>

                   </property>

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

              </bean>

              <bean id="myJmsTemplate" class="org.springframework.jms.core.JmsTemplate">

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

              <property name="defaultDestination" ref="myBrokerSendDestination" />

              </bean>

             

             

            Thanks.

            • 3. Re: JBoss HornetQ setup and Spring
              jbertram

              I did look at that simple example(GC: examples / jms / spring-integration / server0 / spring-jms-beans.xml - GrepCode Source).

              But it didn't help me much.

              Sorry for the confusion.  I was looking at the Spring Integration example in Apache ActiveMQ Artemis which eschews JNDI in favor of directly instantiating the connection factory and destination objects.  I thought this would help you since you were having trouble with JNDI.  In case you weren't aware, the HornetQ code-base was donated to Apache ActiveMQ and has morphed into the Artemis broker.  There will be no future development of HornetQ itself.  All work is now being done on Artemis.

               

              I get this -  javax.naming.NameNotFoundException: queue/test4 -- service jboss.naming.context.java.queue.test4

              I recommend you use this:

               

                  <queue name="test4">

                      <entry name="java:/queue/test4"/>

                      <entry name="java:jboss/exported/jms/queue/test4"/>

                  </queue>

               

              Notice the "java:/" prefix on the first entry.  This is the same pattern that your connection factory is using and it seems to be working just fine.

              • 4. Re: JBoss HornetQ setup and Spring
                rm0han

                Thanks. But it didn't work. I am deploying my EAR in JBoss. I think I am unable to understand the logic behind the JNDI lookup syntax.

                 

                 

                Mohan

                • 5. Re: JBoss HornetQ setup and Spring
                  jbertram

                  Then just instantiate the connection factory and destination(s) directly and don't use JNDI.

                  • 6. Re: JBoss HornetQ setup and Spring
                    rm0han

                    I have switched to artemis.

                    But I am about to give up. JEE cannot be so difficult.

                     

                    1. Should all the artemis resource be loaded into the EAR's META-INF or the WAR'S WEB-INF ?

                    2. How do I create a template like 'regResponseJmsTemplate' shown in this file ?

                     

                     

                    No qualifying bean of type [org.springframework.jms.core.JmsTemplate] found for dependency

                     

                    <beans xmlns="http://www.springframework.org/schema/beans"

                           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                           xsi:schemaLocation="http://www.springframework.org/schema/beans

                               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

                     

                     

                       <bean id="securityManager" class="org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManagerImpl">

                          <constructor-arg>

                             <bean class="org.apache.activemq.artemis.core.config.impl.SecurityConfiguration">

                                <constructor-arg name="users">

                                   <map>

                                      <entry key="guest" value="guest"/>

                                   </map>

                                </constructor-arg>

                                <constructor-arg name="roles">

                                   <map>

                                      <entry key="guest">

                                         <list>

                                            <value>guest</value>

                                         </list>

                                      </entry>

                                   </map>

                                </constructor-arg>

                                <property name="DefaultUser" value="guest"/>

                             </bean>

                          </constructor-arg>

                       </bean>

                     

                     

                       <bean id="EmbeddedJms" class="org.apache.activemq.artemis.integration.spring.SpringJmsBootstrap" init-method="start"

                             destroy-method="stop">

                           <property name="SecurityManager" ref="securityManager"/>

                       </bean>

                     

                     

                      <!-- Spring JMS Template -->

                       <bean id="regResponseJmsTemplate" class="org.springframework.jms.core.JmsTemplate">

                         <property name="connectionFactory">

                           <ref local="connectionFactory"/>

                         </property>

                       </bean>

                     

                     

                       <bean id="connectionFactory" class="org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory">

                          <constructor-arg value="false"/>

                          <constructor-arg>

                             <bean class="org.apache.activemq.artemis.api.core.TransportConfiguration">

                                <constructor-arg value="org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory"/>

                             </bean>

                          </constructor-arg>

                       </bean>

                     

                     

                     

                     

                       <bean id="exampleQueue" class="org.apache.activemq.artemis.jms.client.ActiveMQQueue">

                          <constructor-arg index="0" value="exampleQueue"/>

                       </bean>

                     

                     

                       <bean id="listener" class="org.apache.activemq.artemis.jms.example.ExampleListener"/>

                     

                     

                       <bean id="MessageSender" class="org.apache.activemq.artemis.jms.example.MessageSender">

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

                          <property name="destination" ref="exampleQueue"/>

                       </bean>

                     

                     

                       <bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">

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

                          <property name="destination" ref="exampleQueue"/>

                          <property name="messageListener" ref="listener"/>

                       </bean>

                     

                     

                    </beans>

                     

                    Update : I have passed this stage after i looked at other good Artemis examples in your git.