1 Reply Latest reply: Oct 27, 2011 5:58 PM by El Mentecato RSS

Failed to create session

El Mentecato Newbie

Using JBoss 5.1.0 + EJB3 plugin with a custom instance made up of basically default + HornetQ 2.2.2.

I have an EAR with an MDB that works well listening to messages on MyQueue/receive. Now I want to do the same from a separate application server (Jetty), but same host, using Spring 3.0.6. That is, I want to create a MDP that replaces the MDB, and will keep hornetq running as it is--embedded in JBoss.

 

this is my spring config:

 

<?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="eventReportListener"/>
   </bean>
     
</beans>

 

My listener looks like this:

 

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(EventReportJMSListener.class);
   
     public void onMessage(Message message) {
      try {
         TextMessage msg = (TextMessage) message;
         logger.info("Consumed message: " + msg.getText());
      }
      catch (Exception ex) {
         ex.printStackTrace();
      }
   }
}   

 

When I deploy my app, I see the following on JBoss' server.log (no errors from my app running on Jetty):

 

 

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)

 

Looks like I just need to somehow specify credentials, but I just don't see where or how. I've looked on the spring and hornetq forums and docs and haven't found a solution. Please help!

  • 1. Re: Failed to create session
    El Mentecato Newbie

    OK, thanks to http://code.google.com/p/joshlong-examples/source/browse/trunk/hornetq-spring-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:

     

    <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:

     

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