3 Replies Latest reply on Jul 4, 2012 4:31 AM by Andy Taylor

    Using Spring-jmstemplates with HornetQ

    raymanf Newbie

      Hi,

      I am using Spring3.1 in a standalone env.


      Recently I success integrate my env with Hornetq2.2.


      I am trying to work with jms template but I get this exception. I think the exception is less concerned to jms but more to using of templates in the container.

       

       

      INFO: HornetQ Server version 2.2.5.Final (HQ_2_2_5_FINAL_AS7, 121) [b214b899-c50b-11e1-82a9-000ffe939094] started
      
      org.springframework.jms.UncategorizedJmsException: Uncategorized exception occured during JMS processing; nested exception is javax.jms.JMSException: Failed to create session factory; nested exception is java.lang.IllegalArgumentException: Error instantiating connector factory "org.hornetq.integration.transports.netty.NettyConnectorFactory"
       at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:316)
       at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:168)
       at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:469)
       at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:543)
       at com.fixgw.server.utils.NotificationsProducer.sendNotification(NotificationsProducer.java:28)
       at com.fixgw.beans.FeedListenerBean.listen(FeedListenerBean.java:28)
       at com.fixgw.test.TriggerBean.doTheListen(TriggerBean.java:52)
       at com.fixgw.test.TriggerBean.start(TriggerBean.java:39)
       at com.fixgw.daemon.FeedDaemon.start(FeedDaemon.java:80)
       at com.fixgw.daemon.FeedDaemon.main(FeedDaemon.java:97)
      Caused by: javax.jms.JMSException: Failed to create session factory
       at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:615)
       at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:121)
       at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:116)
       at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:184)
       at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:456)
       ... 7 more
      Caused by: java.lang.IllegalArgumentException: Error instantiating connector factory "org.hornetq.integration.transports.netty.NettyConnectorFactory"
       at org.hornetq.utils.ClassloadingUtil$1.run(ClassloadingUtil.java:31)
       at java.security.AccessController.doPrivileged(Native Method)
       at org.hornetq.utils.ClassloadingUtil.safeInitNewInstance(ClassloadingUtil.java:15)
       at org.hornetq.core.client.impl.ClientSessionFactoryImpl.instantiateConnectorFactory(ClientSessionFactoryImpl.java:1192)
       at org.hornetq.core.client.impl.ClientSessionFactoryImpl.<init>(ClientSessionFactoryImpl.java:179)
       at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:590)
       at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:611)
       ... 11 more
      Caused by: java.lang.ClassNotFoundException: org.hornetq.integration.transports.netty.NettyConnectorFactory
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at org.hornetq.utils.ClassloadingUtil$1.run(ClassloadingUtil.java:26)
       ... 17 more
      


      With this class I am producing message and this is where I am getting the exception.

       

      package com.fixgw.server.utils;
      @Service("notificationsProducer")
      public class NotificationsProducer
      {
       @Autowired
       JmsTemplate jmsTemplate;
      
       public void sendNotification(final String message)
       {
       jmsTemplate.send("queue.Notification", new MessageCreator()
       {
       @Override
       public Message createMessage(Session session) throws JMSException
       {
       return session.createObjectMessage(message);
       }
       });
      
       }
      

      }

       

       

      and this is my applicationContext.xml:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
      
      
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-3.0.xsd
          http://www.springframework.org/schema/aop 
          http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
      
      
      
       <context:annotation-config />
      
      
       <context:component-scan base-package="com.fixgw">
       </context:component-scan>
      
      
      
       <!--     start a JMX Server      -->
       <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean" />
      
      
       <bean id="FeedListenerBean" class="com.fixgw.beans.FeedListenerBean">
       </bean>
      
       <bean id="TriggerBean" class="com.fixgw.test.TriggerBean">
       </bean>
      
      
      
      
       <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
       <property name="beans">
       <map>
       <entry key="Server:name=HttpAdaptor">
       <bean class="mx4j.tools.adaptor.http.HttpAdaptor">
       <property name="port" value="8000" />
       <property name="host" value="0.0.0.0" />
       <property name="processor">
       <bean class="mx4j.tools.adaptor.http.XSLTProcessor" />
       </property>
       </bean>
       </entry>
       <entry key="bean:name=TriggerBean" value-ref="TriggerBean" />
      
       </map>
       </property>
       <property name="listeners">
       <list>
       <!--
       let the HttpAdapter be started after it is registered in the
       MBeanServer
       -->
       <bean class="com.fixgw.jmx.HttpAdaptorMgr">
       <property name="mbeanServer" ref="mbeanServer" />
       </bean>
       </list>
       </property>
       </bean>
      
       <bean name="namingServerImpl" class="org.jnp.server.NamingBeanImpl"
       init-method="start" destroy-method="stop" />
      
       <bean name="namingServer" class="org.jnp.server.Main" init-method="start"
       destroy-method="stop">
       <property name="namingInfo" ref="namingServerImpl" />
       <property name="port" value="1099" />
       <property name="bindAddress" value="localhost" />
       <property name="rmiPort" value="1098" />
       <property name="rmiBindAddress" value="localhost" />
       </bean>
      
      
      
       <bean name="fileConfiguration" class="org.hornetq.core.config.impl.FileConfiguration"
       init-method="start" destroy-method="stop" />
      
       <bean name="hornetQSecurityManagerImpl"
       class="org.hornetq.spi.core.security.HornetQSecurityManagerImpl" />
      
       <!-- The core server -->
       <bean name="hornetQServerImpl" class="org.hornetq.core.server.impl.HornetQServerImpl">
       <constructor-arg ref="fileConfiguration" />
       <constructor-arg ref="mbeanServer" />
       <constructor-arg ref="hornetQSecurityManagerImpl" />
       </bean>
      
       <!-- The JMS server -->
       <bean name="jmsServerManagerImpl" class="org.hornetq.jms.server.impl.JMSServerManagerImpl"
       init-method="start" destroy-method="stop" depends-on="namingServer">
       <constructor-arg ref="hornetQServerImpl" />
       </bean>
      
      
      
      
       <bean name="connectionFactory" class="org.hornetq.jms.client.HornetQJMSConnectionFactory">
       <constructor-arg name="ha" value="false" />
       <constructor-arg>
       <bean class="org.hornetq.api.core.TransportConfiguration">
       <constructor-arg
       value="org.hornetq.integration.transports.netty.NettyConnectorFactory" />
       <constructor-arg>
       <map key-type="java.lang.String" value-type="java.lang.Object">
       <entry key="port" value="5445"></entry>
       </map>
       </constructor-arg>
       </bean>
       </constructor-arg>
       </bean>
      
      
      
      
       <bean name="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
       <property name="connectionFactory" ref="connectionFactory"></property>
       <property name="defaultDestinationName" value="queue.Notifications" />
       </bean>
      
      
      
       <bean id="notificationsQueue" class="org.springframework.jndi.JndiObjectFactoryBean"
       depends-on="jmsServerManagerImpl">
       <property name="jndiName">
       <value>/queue/Notifications</value>
       </property>
       </bean>
      
      
       <bean id="inVMConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"
       depends-on="jmsServerManagerImpl">
       <property name="jndiName">
       <value>java:/ConnectionFactory</value>
       </property>
       </bean>
      
      </beans>
      


       

       

      Thanks,

      ray.

        • 1. Re: Using Spring-jmstemplates with HornetQ
          Andy Taylor Master

          its just a classpath issue, make sure the hornetq and netty jars are in the classpath

          • 2. Re: Using Spring-jmstemplates with HornetQ
            raymanf Newbie

            They are. when I Didnt use jms telmpalte that worked just fine:

             

             

             

             

            @Service("FeedListenerBean")

            public class FeedListenerBean implements MessageListener

            {

             

             

                      @Autowired

                      Queue notificationsQueue;

             

             

                      @Autowired

                      ConnectionFactory inVMConnectionFactory;

             

             

                      private Connection notificationsQueueConnection;

             

             

                      @PostConstruct

                      public void init() throws Exception

                      {

                                notificationsQueueConnection = inVMConnectionFactory.createConnection();

                                Session notificationsQueueSession = notificationsQueueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);

                                MessageConsumer notificationsQueueConsumer = notificationsQueueSession.createConsumer(notificationsQueue);

                                notificationsQueueConsumer.setMessageListener(this);

                                notificationsQueueConnection.start();

                      }

             

             

                      @PreDestroy

                      public void destroy() throws Exception

                      {

                                if (notificationsQueueConnection != null)

                                          notificationsQueueConnection.close();

                      }

             

             

                      @Override

                      public void onMessage(Message message)

                      {

                                if (message instanceof TextMessage)

                                {

                                          try

                                          {

                                                    String text = ((TextMessage) message).getText();

                                                    System.out.println("The Notification Messageeee is : \n" + text);

                                          }

                                          catch (JMSException ex)

                                          {

                                                    throw new RuntimeException(ex);

                                          }

                                }

                                else

                                {

                                          throw new IllegalArgumentException("Message must be of type TextMessage");

                                }

                      }

             

             

            }

            • 3. Re: Using Spring-jmstemplates with HornetQ
              Andy Taylor Master

              if you are getting a class not found then the classes arent available in the classpath, I would investigate why this is.