4 Replies Latest reply on Oct 19, 2011 4:30 AM by azrael

    Problem send JMS to QUEUE using JNDI

    azrael Newbie

      I have a problem with configuration of JMS/QUEUE. I read few articles about how to configure JMS QUEUE/TOPIC using HORNET_Q. I saw examples in HORNET_Q, but nothing works. I have no idea what's wrong .

       

      1) I use jboss-6.1.0.Final

      2) Configuration: all

      3) I put: myapp-hornetq-jms.xml into deploy folder

       

      File looks like:

      <configuration xmlns="urn:hornetq"

                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                  xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">

       

          <connection-factory name="ConnectionFactory">

              <connectors>

                  <connector-ref connector-name="netty"/>

              </connectors>

              <entries>

                  <entry name="/ConnectionFactory"/>

              </entries>

          </connection-factory>           

         

          <queue name="myApp.UserUsedQueue">

              <entry name="queue/myApp.UserUsedQueue"/>

          </queue>

       

      </configuration>

       

       

      4) When I deploy file myapp-hornetq-jms.xml, I see on the console:

      08:56:40,875 INFO  [HornetQServerImpl] trying to deploy queue myApp.UserUsedQueue

       

      Nothing else.

       

      5) I wrote sample standalone Client to send JMS to this queue:

       

      public class ClientTesterJMS {

       

       

          public static void main(final String args[]) {

              System.out.println("####### START MAIN #######");

       

              sendJMS();

             

              System.out.println("####### FINISH MAIN #######");

          }

       

       

         

              public static Context getContext() throws Exception {

                  Properties prop = System.getProperties();

                  prop.put("java.naming.factory.initial",    "org.jnp.interfaces.NamingContextFactory");

                  prop.put("java.naming.provider.url", "jnp://localhost:1099");

                  prop.put("java.naming.factory.url.pkgs", "org.jnp.interfaces:org.jboss.naming");

                  return new InitialContext(prop);

              }

         

         

          public static void sendJMS() {

              QueueConnection     queueConnection = null;

              Queue               queue = null;       

         

              QueueSession queueSession = null;

              QueueSender queueSender = null;

              ObjectMessage messageObj = null;

         

              try {

                    Context context = null;

                    QueueConnectionFactory queueConnectionFactory = null;

       

                  System.out.println("START"); 

                    context = getContext();

                  System.out.println("getContext JBOSS");   

                  queue = (Queue) context.lookup("queue/myApp.UserUsedQueue");

                  System.out.println("getContext queue");

                   

                  //Create a QueueConnection

                  ConnectionFactory qf = (ConnectionFactory)context.lookup("/ConnectionFactory");

                  System.out.println("getContext queueConnectionFactory");

                  Connection con = qf.createConnection();  //---> THIS LINE MAKE ERROR

                  System.out.println("queueConnection");

             

                  queueSession = queueConnection.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); //1

                  System.out.println("Create QueueSession");

                  queueSender = queueSession.createSender(queue);

                  System.out.println("Create QueueSender");

         

                  //SAMPLE OBJECT TO SEND TO QUEUE

                  Collection col = new ArrayList();;

                  col.add(new Long(1300000));

                  Vector vec = new Vector();

                  vec.add("1000");     //scnId

                  vec.add("Y");         //usedFlag

                  vec.add("OK");         //used

                  vec.add(col);       

                 

                  messageObj = queueSession.createObjectMessage(vec);

                  System.out.println("createObjMessage");

                 

                  queueSender.send(messageObj);

                  System.out.println("send JMS OK");

              } catch (Exception e)    {

                  e.printStackTrace();

              } finally {

                  if (queueSession != null)

                      try { queueSession.close();    } catch (Exception e)    {}

                  if(queueConnection != null)

                      try { queueConnection.close(); } catch (Exception e) {}

              }

          }

      }

       

       

      6) On the console, when I run my Client

       

       

      ####### START MAIN #######

      START

      getContext JBOSS

      getContext queue

      getContext queueConnectionFactory

      2011-10-18 10:02:07 org.hornetq.core.logging.impl.JULLogDelegate error

      SEVERE: hornetq-version.properties is not available

      java.lang.RuntimeException: hornetq-version.properties is not available

              at org.hornetq.utils.VersionLoader.load(VersionLoader.java:101)

              at org.hornetq.utils.VersionLoader.<clinit>(VersionLoader.java:73)

              at org.hornetq.core.remoting.impl.netty.NettyConnector.start(NettyConnec

      tor.java:381)

              at org.hornetq.core.client.impl.ClientSessionFactoryImpl.getConnection(C

      lientSessionFactoryImpl.java:1009)

              at org.hornetq.core.client.impl.ClientSessionFactoryImpl.getConnectionWi

      thRetry(ClientSessionFactoryImpl.java:897)

              at org.hornetq.core.client.impl.ClientSessionFactoryImpl.connect(ClientS

      essionFactoryImpl.java:212)

              at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(S

      erverLocatorImpl.java:602)

              at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInter

      nal(HornetQConnectionFactory.java:611)

              at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(Horn

      etQConnectionFactory.java:121)

              at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(Horn

      etQConnectionFactory.java:116)

              at ClientTesterJMS.sendJMS(ClientTesterJMS.java:71)

              at ClientTesterJMS.main(ClientTesterJMS.java:27)

      2011-10-18 10:02:07 org.hornetq.core.logging.impl.JULLogDelegate warn

      WARNING: connector.create or connectorFactory.createConnector should never throw

      an exception, implementation is badly behaved, but we'll deal with it anyway.

      java.lang.RuntimeException: hornetq-version.properties is not available

              at org.hornetq.utils.VersionLoader.getVersion(VersionLoader.java:87)

              at org.hornetq.core.remoting.impl.netty.NettyConnector.start(NettyConnec

      tor.java:381)

              at org.hornetq.core.client.impl.ClientSessionFactoryImpl.getConnection(C

      lientSessionFactoryImpl.java:1009)

              at org.hornetq.core.client.impl.ClientSessionFactoryImpl.getConnectionWi

      thRetry(ClientSessionFactoryImpl.java:897)

              at org.hornetq.core.client.impl.ClientSessionFactoryImpl.connect(ClientS

      essionFactoryImpl.java:212)

              at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(S

      erverLocatorImpl.java:602)

              at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInter

      nal(HornetQConnectionFactory.java:611)

              at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(Horn

      etQConnectionFactory.java:121)

              at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(Horn

      etQConnectionFactory.java:116)

              at ClientTesterJMS.sendJMS(ClientTesterJMS.java:71)

              at ClientTesterJMS.main(ClientTesterJMS.java:27)

      2011-10-18 10:02:07 org.hornetq.core.logging.impl.JULLogDelegate warn

      WARNING: Tried 1 times to connect. Now giving up on reconnecting it.

      javax.jms.JMSException: Failed to create session factory

              at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInter

      nal(HornetQConnectionFactory.java:615)

              at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(Horn

      etQConnectionFactory.java:121)

              at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(Horn

      etQConnectionFactory.java:116)

              at ClientTesterJMS.sendJMS(ClientTesterJMS.java:71)

              at ClientTesterJMS.main(ClientTesterJMS.java:27)

      Caused by: HornetQException[errorCode=2 message=Cannot connect to server(s). Tri

      ed with all available servers.]

              at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(S

      erverLocatorImpl.java:619)

              at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInter

      nal(HornetQConnectionFactory.java:611)

              ... 4 more

      ####### KONIEC MAIN #######