6 Replies Latest reply on Jun 17, 2011 6:08 AM by piotrekde

    HornetQ 2.2.2.Final and Spring Framework integration.

    piotrekde

      Hello,

       

      In our project built on a top of Spring Framework we use HornetQ in 2.0.0.GA version. Now, we'd like to migrate to the newest 2.2.2.Final release and use clustering option.


      Could you please provide sample Spring context configuration which works with clustered 2.2.2.Final?

       

      We've tried using HornetQJMSClient (http://docs.jboss.org/hornetq/2.2.2.Final/api/org/hornetq/api/jms/HornetQJMSClient.html), as it has  DiscoveryGroupConfiguration constructor parameter, however it causes many errors about not closed connections.

       

      Here it is (version for single broker):

       

        <beans:bean id="connectionFactory"
          class="org.springframework.jms.connection.CachingConnectionFactory">
          <beans:property name="targetConnectionFactory" ref="targetConnectionFactory" />
          <beans:property name="sessionCacheSize" value="10" />
          <beans:property name="cacheProducers" value="false" />
        </beans:bean>
      
          <util:constant id="QUEUE_XA_CF" static-field="org.hornetq.api.jms.JMSFactoryType.QUEUE_XA_CF" />
      
      
          <beans:bean name="targetConnectionFactory" class="org.hornetq.api.jms.HornetQJMSClient" factory-method="createConnectionFactoryWithoutHA">
            <beans:constructor-arg index="0" ref="QUEUE_XA_CF"/>
            <beans:constructor-arg index="1" ref="transportConfiguration"/>
          </beans:bean>
      
            <beans:bean name="transportConfiguration" class="org.hornetq.api.core.TransportConfiguration">
              <beans:constructor-arg
                value="org.hornetq.integration.transports.netty.NettyConnectorFactory" />
              <beans:constructor-arg>
                <beans:map key-type="java.lang.String" value-type="java.lang.Object">
                  <beans:entry key="host" value="localhost" />
                  <beans:entry key="port" value="5445" />
                </beans:map>
              </beans:constructor-arg>
            </beans:bean>
      
      

       

       

      Generally, we'd like to configure targetConnectionFactory with clustering option (multicast addressing), and then pass it to Spring CachingConnectionFactory.

      Any help is appreciated. Thanks in advance,

      Piotr

        • 2. Re: HornetQ 2.2.2.Final and Spring Framework integration.
          piotrekde

          Thanks Clebert,

           

          I've read this document before and honestly I don't know how these examples can be applied to spring application using standard connection factory.

          As I understand, the first listening is configuration of broker itself. In my case, broker works as an external application (actually it's whole cluster available on multicast address). The second one, defines message listener container used sometimes in Spring applications, but it doesn't fit all cases (including mine). We need standard connection factory reference to the brokers cluster.

          • 3. Re: HornetQ 2.2.2.Final and Spring Framework integration.
            ataylor

            We've tried using HornetQJMSClient (http://docs.jboss.org/hornetq/2.2.2.Final/api/org/hornetq/api/jms/HornetQJMSClient.html), as it has  DiscoveryGroupConfiguration constructor parameter, however it causes many errors about not closed connections.

            This is the way you should do it, if you are getting errors maybe we can help solve them

            • 4. Re: HornetQ 2.2.2.Final and Spring Framework integration.
              ataylor

              If you haver a maven project that i can mess about with, i'll take a look.

              • 5. Re: HornetQ 2.2.2.Final and Spring Framework integration.
                piotrekde

                Thank you very much! I'll try to isolate the problem into small maven project and let you know.

                • 6. Re: HornetQ 2.2.2.Final and Spring Framework integration.
                  piotrekde

                  When I was isolating problem, I've worked out solution for standalone server.

                  Here is valid configuration for 2.2.2.Final and connection factory:

                   

                   

                    <bean id="connectionFactory"
                      class="org.springframework.jms.connection.CachingConnectionFactory">
                      <property name="targetConnectionFactory" ref="targetConnectionFactory" />
                      <property name="sessionCacheSize" value="100" />
                      <property name="cacheProducers" value="true" />
                    </bean>
                  
                    <util:constant id="QUEUE_XA_CF"
                      static-field="org.hornetq.api.jms.JMSFactoryType.QUEUE_XA_CF" />
                  
                    <bean name="targetConnectionFactory" class="org.hornetq.api.jms.HornetQJMSClient"
                      factory-method="createConnectionFactoryWithoutHA">
                      <constructor-arg index="0" ref="QUEUE_XA_CF" />
                      <constructor-arg index="1" ref="transportConfiguration" />
                    </bean>
                  
                    <bean name="transportConfiguration"
                      class="org.hornetq.api.core.TransportConfiguration">
                      <constructor-arg
                        value="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory" />
                      <constructor-arg>
                        <map key-type="java.lang.String" value-type="java.lang.Object">
                          <entry key="host" value="localhost" />
                          <entry key="port" value="5445" />
                        </map>
                      </constructor-arg>
                    </bean>
                  
                  

                   

                  Artifacts and their versions are following:

                   

                   

                      <dependency>
                        <groupId>org.hornetq</groupId>
                        <artifactId>hornetq-core-client</artifactId>
                        <version>${hornetq.version}</version>
                      </dependency>
                  
                  
                      <dependency>
                        <groupId>org.hornetq</groupId>
                        <artifactId>hornetq-jms-client</artifactId>
                        <version>${hornetq.version}</version>
                      </dependency>
                  
                  
                      <dependency>
                        <groupId>org.hornetq</groupId>
                        <artifactId>hornetq-spring-integration</artifactId>
                        <version>${hornetq.version}</version>
                      </dependency>
                  
                  
                      <dependency>
                        <groupId>org.jboss.netty</groupId>
                        <artifactId>netty</artifactId>
                        <version>3.2.4.Final</version>
                      </dependency>
                  
                  

                   

                   

                  I attached maven project using 2.2.2.Final and spring integration.

                  It's extended producer-consumer example - producer sends message, which is received by consumer, transformed and sent back.

                   

                  HornetQ must define following queue:

                   

                          <queue name="hornetq.demo.producer.queue">
                                 <entry name="/queue/HornetQDemoProducerQueue"/>
                          </queue>
                  
                  

                   

                  Now, I'll try with cluster mode and let you know.