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

    Problem send JMS to QUEUE using JNDI

    azrael

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

        • 1. Re: Problem send JMS to QUEUE using JNDI
          ataylor

          This looks like a classpath issue on the client side, are you sure you have all the correct jars?

          • 2. Re: Problem send JMS to QUEUE using JNDI
            azrael

            Client has below jar's on classpath. Library, I get from JBOSS directory.

             

            concurrent.jar

            hornetq-bootstrap.jar

            hornetq-core.jar

            hornetq-jboss-as-integration.jar

            hornetq-jms-client.jar

            hornetq-jms.jar

            hornetq-logging.jar

            jboss-client.jar

            jboss-common-core.jar

            jboss-ejb-api_3.1_spec.jar

            jboss-integration.jar

            jboss-jms-api_1.1_spec.jar

            jboss-logging.jar

            jboss-remoting.jar

            jboss-security-spi.jar

            jboss-serialization.jar

            jboss-transaction-api_1.1_spec.jar

            jbosssx-client.jar

            jnp-client.jar

            netty.jar

             

             

            Additionally, I read few articles:

            http://community.jboss.org/thread/170077

            http://209.132.182.48/thread/169712

             

            But it didn't solve my problem.

            • 3. Re: Problem send JMS to QUEUE using JNDI
              ataylor

              It has to be environmental, the client is trying to find the 'hornetq-version.properties' file which is in both hornetq-core.jar and hornetq-core-client.jar (take a look) but cant find it on the classpath. You could try debugging to see why?

              1 of 1 people found this helpful
              • 4. Re: Problem send JMS to QUEUE using JNDI
                azrael

                Thanks a lot.

                 

                Problem was with classpath.

                 

                I run client like this.

                runJMS.bat

                ----------

                @set JBOSS_LIB=jboss

                java -Djava.ext.dirs="%JBOSS_LIB%" ClientTesterJMS

                 

                 

                I change this script to this and it works.

                java -classpath .;jboss\jnp-client.jar;jboss\jboss-logging.jar;jboss\jboss-ejb-api_3.1_spec.jar;jboss\jboss-client.jar;jboss\jboss-security-spi.jar;jboss\jboss-transaction-api_1.1_spec.jar;jboss\jboss-serialization.jar;jboss\jboss-jms-api_1.1_spec.jar;jboss\hornetq-jms-client.jar;jboss\hornetq-core-client.jar;jboss\netty.jar ClientTesterJMS

                 

                Once more, thanks.