Announcement Announcement Module
Collapse
No announcement yet.
Connecting to HornetQ + JBoss 5.1.0 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Connecting to HornetQ + JBoss 5.1.0

    I've been trying to create a MDP to listen to messages on a queue that is on hornetq 2.2.2 which runs inside JBoss 5.1.0. My spring app is not running on the same JBoss server, but on a Jetty app server on the same host. HornetQ's samples only show the embedded JMS scenario, and didn't see anything on this forum or on hornetq's that shows how to configure spring to do this. Note that a MDB running on an ear file deployed on this JBoss instance works fine, and I want to replace it with a spring-based MDP.

    Following is one of the configurations that almost works. My listener:

    Code:
    import javax.jms.Message;
    import javax.jms.MessageListener;
    import javax.jms.TextMessage;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
     
    public class MyJMSListener implements MessageListener {
         private static final Logger logger = LoggerFactory.getLogger(MyJMSListener.class);
       
         public void onMessage(Message message) {
          try {
             TextMessage msg = (TextMessage) message;
             logger.info("Consumed message: " + msg.getText());
          }
          catch (Exception ex) {
             ex.printStackTrace();
          }
       }
    }
    My spring config (snippet):

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <beans >
        <!-- other stuff suppressed for clarity -->
    
       <jee:jndi-lookup id="connectionFactory" jndi-name="java:/ConnectionFactory"
          cache="true" resource-ref="true" lookup-on-startup="true" expected-type=""
          proxy-interface="javax.jms.ConnectionFactory" >
          <jee:environment>
                java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
                java.naming.provider.url=jnp://localhost:1099
                java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
          </jee:environment>
       </jee:jndi-lookup>
       
       <jee:jndi-lookup id="eventsQueue" jndi-name="/queue/MyQueue/receive"
            cache="true" resource-ref="true" lookup-on-startup="true"
            proxy-interface="javax.jms.Queue" >
            <jee:environment>
                java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
                java.naming.provider.url=jnp://localhost:1099
                java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
            </jee:environment>
        </jee:jndi-lookup>
           
       <bean id="myListener"   class="com.mycompany.MyJMSListener" />
             
       <bean id="jmsContainer"
          class="org.springframework.jms.listener.DefaultMessageListenerContainer">
          <property name="connectionFactory" ref="connectionFactory"/>
          <property name="destination" ref="eventsQueue"/>
          <property name="messageListener" ref="myListener"/>
       </bean>
    </beans>
    And this is the resulting error (if all I need is to specify the username/password of the JMS server, just simply tell me where to specify that in the configuration, because it's not obvious to me):

    Code:
    ERROR [org.hornetq.core.protocol.core.impl.HornetQPacketHandler] (Old I/O server worker (parentId: 21883281, [id: 0x014de991, /127.0.0.1:5445])) Failed to create session 
    HornetQException[errorCode=105 message=Unable to validate user: null]
    at org.hornetq.core.security.impl.SecurityStoreImpl.authenticate(SecurityStoreImpl.java:141)
              at org.hornetq.core.server.impl.HornetQServerImpl.createSession(HornetQServerImpl.java:916)
              at org.hornetq.core.protocol.core.impl.HornetQPacketHandler.handleCreateSession(HornetQPacketHandler.java:168)
              at org.hornetq.core.protocol.core.impl.HornetQPacketHandler.handlePacket(HornetQPacketHandler.java:84)
              at org.hornetq.core.protocol.core.impl.ChannelImpl.handlePacket(ChannelImpl.java:474)
              at org.hornetq.core.protocol.core.impl.RemotingConnectionImpl.doBufferReceived(RemotingConnectionImpl.java:496)
              at org.hornetq.core.protocol.core.impl.RemotingConnectionImpl.bufferReceived(RemotingConnectionImpl.java:457)
              at org.hornetq.core.remoting.server.impl.RemotingServiceImpl$DelegatingBufferHandler.bufferReceived(RemotingServiceImpl.java:459)
              at org.hornetq.core.remoting.impl.netty.HornetQChannelHandler.messageReceived(HornetQChannelHandler.java:73)
              at org.jboss.netty.channel.SimpleChannelHandler.handleUpstream(SimpleChannelHandler.java:100)
              at org.jboss.netty.channel.StaticChannelPipeline.sendUpstream(StaticChannelPipeline.java:362)
              at org.jboss.netty.channel.StaticChannelPipeline$StaticChannelHandlerContext.sendUpstream(StaticChannelPipeline.java:514)
              at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:287)
              at org.hornetq.core.remoting.impl.netty.HornetQFrameDecoder2.decode(HornetQFrameDecoder2.java:169)
              at org.hornetq.core.remoting.impl.netty.HornetQFrameDecoder2.messageReceived(HornetQFrameDecoder2.java:134)
              at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)
              at org.jboss.netty.channel.StaticChannelPipeline.sendUpstream(StaticChannelPipeline.java:362)
              at org.jboss.netty.channel.StaticChannelPipeline.sendUpstream(StaticChannelPipeline.java:357)
              at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:274)
              at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:261)
              at org.jboss.netty.channel.socket.oio.OioWorker.run(OioWorker.java:90)
              at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
              at org.jboss.netty.util.internal.IoWorkerRunnable.run(IoWorkerRunnable.java:46)
              at org.jboss.netty.util.VirtualExecutorService$ChildExecutorRunnable.run(VirtualExecutorService.java:181)
              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
              at java.lang.Thread.run(Thread.java:662)

  • #2
    OK, thanks to http://code.google.com/p/joshlong-ex...-examples/?r=8, I was able to figure out how to configure a connectionFactory with authentication and connect to the hornetq JMS server. Here's the pertinent config items:

    Code:
    <context:component-scan base-package="com.mycompany"></context:component-scan>
       <context:annotation-config />
       <aop:aspectj-autoproxy/>
       <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:ignoreUnresolvablePlaceholders="true" />
    
       <bean id="jmsConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory" p:targetConnectionFactory-ref="jmsUserCredentialsConnectionFactory" p:reconnectOnException="true" />
    
       <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager" p:connectionFactory-ref="jmsConnectionFactory" p:nestedTransactionAllowed="true"/>
    
       <bean id="jmsUserCredentialsConnectionFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter" p:username="${JMS_SERVER_USERNAME}" p:password="${JMS_SERVER_PASSWORD}" >
            <property name="targetConnectionFactory">
                <bean class="org.hornetq.jms.client.HornetQJMSConnectionFactory">
                    <constructor-arg type="boolean" value="false"/>
                    <constructor-arg>
                        <bean 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="${JMS_SERVER_HOST}"/>
                                    <entry key="port" value="${JMS_SERVER_PORT}"/>
                                </map>
                            </constructor-arg>
                        </bean>
                    </constructor-arg>
                    <!-- <property name="failoverOnServerShutdown" value="true"/> -->
                    <property name="reconnectAttempts" value="5"/>
                </bean>
            </property>
        </bean>
        
       <bean class="org.springframework.jms.listener.DefaultMessageListenerContainer"
              p:destinationName="volt.EventReport.receive"
              p:transactionManager-ref="jmsTransactionManager"
              p:connectionFactory-ref="jmsConnectionFactory"
              p:concurrentConsumers="5" >
            <property name="messageListener">
                <bean class="org.springframework.jms.listener.adapter.MessageListenerAdapter"
                 p:defaultListenerMethod="onMessage">
                    <property name="delegate">
                        <bean class="com.mycompany.MyMDP"/>
                    </property>
                </bean>
            </property>
       </bean>
    Constants come from a properties file, and my MDP is simply a pure POJO:

    Code:
    public class MyMDP {
       public void onMessage(String message) throws Throwable {
          logger.info("Received message: " + message.toString());
       }
    }

    Comment

    Working...
    X