8 Replies Latest reply on Aug 28, 2011 12:04 PM by ataylor

    Spring integration with Remote HornetQ 2.2.x instance?

    sboscarine

      Hello All,

      I wanted to prototype a distributed application in which a legacy application has a listener to a remote HornetQ 2.2 instance.  My legacy application is running Spring 2.5 in JBoss 4.3 EAP.

       

      The HornetQ examples I found, such as http://docs.jboss.org/hornetq/2.2.5.Final/user-manual/en/html/spring.integration.html , all bootstrap a JMS container. 

       

      Is there any sample code, instructions, or tutorials that show how to get Spring wired with a remote HornetQ server?

       

      Any leads in the right direction would be greatly appreciated!

      Steven

        • 1. Re: Spring integration with Remote HornetQ 2.2.x instance?
          ataylor

          Is there any sample code, instructions, or tutorials that show how to get Spring wired with a remote HornetQ server?

          what do you mean by remote server, do you want to create a server in spring or just a client

          • 2. Re: Spring integration with Remote HornetQ 2.2.x instance?
            sboscarine

            Hello Andy,

            It appears your current example creates a server in Spring.  I concede I may very well be mistaken, but there appears a lot of "magic" going on regarding exposing queues with the Spring bootstrap.  It's a nice prototype and I got it working, but I need the server on a separate physical machine.

             

            As we are investingating HornetQ for performance and scalability gains for a very large app, I wanted to prototype and benchmark multiple computers registering listeners to a standalone HornetQ instance.  My prototype will be across dozens of physical machines. The end design goal is to have multiple Queues, with failover, on their own boxes.  The distributed business logic I am prototyping will be replicated on multple clients and listeners across dozens of physical machines.  However, my immediate goal is to prototype behavior with 1 machine as a dedicated queue and benchmark load charactersistics and reponse times as physical machines are added.

             

            I've figured out how to post messages, now I need to write the code to process them.

             

            I am stuck getting org.springframework.jms.listener.DefaultMessageListenerContainer working with my remote server.  Say I have HornetQ running happily on 192.168.1.111, port 5445.  Here's my TransportConfiguration:

            <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="192.168.1.111" />
                        <entry key="port" value="5445" />
                    </map>
                </constructor-arg>
            </bean>
            

             

            How can I get the Spring ExampleListener you bundled (http://anonsvn.jboss.org/repos/hornetq/trunk/examples/jms/spring-integration/src/org/hornetq/jms/example/ExampleListener.java) wired to that server and have it listen to queue "foo/bar"?

             

            I noticed http://anonsvn.jboss.org/repos/hornetq/trunk/examples/jms/spring-integration/server0/spring-jms-beans.xml however, "/queue/exampleQueue" is a bean name and not a String, correct?  Who registered that bean?  How can I register remote queues?

             

            Thanks,
            Steven

            • 3. Re: Spring integration with Remote HornetQ 2.2.x instance?
              ataylor

              Im not sure what you mean by expose queues, if you are running HornetQ standalone then just install the distro and configure your jms resources in the hornetq-jms.xml file.

               

              Regarding the spring configuration for the client i'm assuming you just configure the listener to lookup the connection factory using jndi, altho ive never used spring so don't really know.

               

              Maybe i'm mis understanding what you are trying to acheive!

              • 4. Re: Spring integration with Remote HornetQ 2.2.x instance?
                sboscarine

                I just want to get your Spring example working for a remote server, not necessarily in a Java EE container.  I am new to JMS, so the JDNI configuration is very new to me. 

                 

                I don't know if JNDI is an option.

                 

                Use Case:

                Pretend I wanted to add a Tomcat client or Java SE to an existing install.  My application has mobile devices sending messages to a queue that require expensive processing time.  We're having issues with "floods."  I know that at 8AM every weekday, I have a spike in load from people starting their workday and registering their devices.  I need to demonstrate that my prototype can add additional capacity, on demand, so the company can stand up additional instance when additional load is anticipated.

                 

                My application is a WAR, so Message Driven Beans are not an option in JBoss EAP 4.3, therefore I need Spring. to get MDB-like functionality, right?

                 

                I am open to other alternatives.  I just need a clean and readable API and our platform doesn't support MDB.  We want to upgrade to JBoss AS 7 or 7.1 and use full Java EE features, but that is a multi-million dollar effort in labor, so obviously management wants to see proof of return on investment

                before greenlighting the expense.

                 

                Therefore, through your examples, I figured out how to post messages.  I've figured out how to pull them off a queue in a manual fashion.  I'd like to write an elegant listener, such as one like you provided in your Spring example. 

                 

                Your Spring example works great when I use the bootstrap class.  Now I want to point the exact same code to a HornetQ instance on a different physical box.  Do you have any suggestions on how I can do that?

                 

                Thanks!

                Steven

                • 5. Re: Spring integration with Remote HornetQ 2.2.x instance?
                  sboscarine

                  I thought of another way to phrase this!

                   

                   

                  I got the following demo below working great.  It's just Bill Burke's Spring Example with my package names:

                   

                  <!-- Embedded HornetQ container. -->
                  <!-- appears to register beans named "/queue/*" based on whatever queues I defined in my config. -->
                  <bean id="EmbeddedJms" class="org.hornetq.integration.spring.SpringJmsBootstrap" init-method="start" destroy-method="stop" />
                  
                  <!-- My listener class...just the example provided by Bill Burke in the HornetQ examples.  implements javax.jms.MessageListener -->
                  <bean id="listener" class="mydomain.ExampleListener" />
                  
                  <!-- Simple client...works great. -->
                  <bean id="MessageSender" class="mydomain.MessageSender">
                       <property name="connectionFactory" ref="ConnectionFactory" />
                       <property name="destination" ref="/queue/foo" />
                  </bean>
                  
                  <!-- The part I am trying to get wired! -->
                  <bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
                       <property name="connectionFactory" ref="ConnectionFactory" />
                       <property name="destination" ref="/queue/foo" />
                       <property name="messageListener" ref="listener" />
                  </bean>
                  

                   

                  This demo is just your Spring demo.  It starts a JMS container on the same host, typically in_vm and works great.  Now I want to run all the Java code against a remote queue.

                   

                  Now how can I run the same code against a queue living on a standalone HornetQ instance on 192.168.1.111?

                   

                  And would the code be any different if I wanted to connect to a JBoss AS 7 Queue?

                   

                  Thanks!

                  Steven

                  • 6. Re: Spring integration with Remote HornetQ 2.2.x instance?
                    ataylor

                    This is really a spring question but basically you have to provide a hornetq connection factory, something like

                     

                     

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

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

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

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

                        </bean>

                     

                        <bean id="hornetQConnectionFactory" class="org.hornetq.jms.client.HornetQJMSConnectionFactory">

                            <constructor-arg name="ha" type="boolean" value="false"/>

                            <!--constructor args for TransportConfiguration ref transportConfiguration bean-->

                        </bean>

                     

                        <bean name="transportConfiguration" class="org.hornetq.api.core.TransportConfiguration">

                            <!--set constructor for netty connector-->

                        </bean>

                     

                    you'll have to fill in the gaps of course.

                     

                    Also you need a destination resolver for the queue/topic, its explained here http://static.springsource.org/spring/docs/2.5.x/reference/jms.html

                    • 7. Re: Spring integration with Remote HornetQ 2.2.x instance?
                      sboscarine

                      Thanks for the response.  I appreciate your patience so far.

                       

                      The gap is what what I was asking about originally.  I think the final piece is the javax.jmx.Destination reference to my Queue.

                       

                      I wasn't ablet to find anything about constructing those in the Spring documentation.

                       

                      How would a JavaSE client hitting a standalone HornetQ instance construct a javax.jmx.Destination to a queue? 

                       

                      If I had a queue named "foo/bar" living on a standalone HornetQ server listening on 192.168.1.111, how can I get a javax.jmx.Destination from a different machine to that Queue? 

                      • 8. Re: Spring integration with Remote HornetQ 2.2.x instance?
                        ataylor

                        A normal client would either lookup the destination via jndi or create it programmatically.  Like i said before this is not really a hornetQ question, this is all done via Spring components. Like i mentioned in the last post you need to use a destination resolver to do this, theres a section on this in the link i posted earlier