2 Replies Latest reply on Jun 2, 2012 7:47 AM by miragpl

    Sending JMS message to queue on JBOSS without JNDI

    miragpl Newbie

      Hi,

       

      I'm trying to send a message to queue running on Jboss without using JNDI lookup

       

       

       

          private static ConnectionFactory createConnectionFactory(int port, String ipAddress)
          {
          Map<String, Object> connectionParams = new HashMap<String, Object>();
              connectionParams.put(TransportConstants.PORT_PROP_NAME, port);
              connectionParams.put(TransportConstants.HOST_PROP_NAME, ipAddress);
      
      
              TransportConfiguration transportConfiguration = new TransportConfiguration(
                      NettyConnectorFactory.class.getName(), connectionParams);
              ConnectionFactory cf = (ConnectionFactory) HornetQJMSClient
                      .createConnectionFactoryWithoutHA(JMSFactoryType.CF, transportConfiguration);
      
      
              return cf;
          }
            public static void sendNoJNDI(int port)
          {
              try
              {
                  ConnectionFactory cf = createConnectionFactory(port, "127.0.0.1");
                  Connection connection = cf.createConnection();
                  Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                  Queue queue = HornetQJMSClient.createQueue("My_Queue");
                  MessageProducer producer = session.createProducer(queue);
                  ObjectMessage message = session.createObjectMessage();
                  message.setStringProperty("Source", "ALIVE");
                  message.setObject("String");
                  producer.send(message);
                  System.out.println("Worked with port: " + port);
              }
              catch (JMSException ex)
              {
                  System.out.println("Failed with port " + port);
              }
          }
      
      
      

       

      I use the above code ufortunately i got an exception in line:

       

          Connection connection = cf.createConnection();

       

      javax.jms.JMSException: Failed to create session factory

                at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:605)

                at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:119)

                at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:114)

                at test.test.jms.SimpleJMSClient.sendNoJNDI(SimpleJMSClient.java:56)

                at test.test.jms.SimpleJMSClient.main(SimpleJMSClient.java:132)

      Caused by: HornetQException[errorCode=2 message=Cannot connect to server(s). Tried with all available servers.]

                at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:774)

       

      The code works perfectly fine when i'm sending a message to HornetQ running in standalone mode.

       

      Regards,

      Marcin