2 Replies Latest reply on Apr 15, 2010 4:09 AM by nnanda

    Not able to connect to Remote HornetQ

    nnanda

      Hi,

       

      I have deployed HornetQ (2.0) within JBoss 5.1 AS and the server is started by binding itself to "my.corp.com" Host name. This JBoss instance is running on a remote server. Now when I am trying to connect it from my machine (which is remote to the server), I am getting following exception

       

      javax.jms.JMSException: Unable to connect to server using configuration org-hornetq-integration-transports-netty-NettyConnectorFactory?host=my-corp-com&port=4350

       

      Following are my configurations:

       

      hornetq-configuration.xml

       

      <connectors>
        <connector name="netty">
          <factory-class>org.hornetq.integration.transports.netty.NettyConnectorFactory</factory-class>
          <param key="host"  value="${jboss.bind.address}"/>
          <param key="port"  value="4085"/>
        </connector>


        <!--<connector name="in-vm">
          <factory-class>org.hornetq.core.remoting.impl.invm.InVMConnectorFactory</factory-class>

        </connector> -->


      </connectors>


      <acceptors>  
        <acceptor name="netty">
          <factory-class>org.hornetq.integration.transports.netty.NettyAcceptorFactory</factory-class>
          <param key="host"  value="${jboss.bind.address}"/>
          <param key="port"  value="4350"/>
        </acceptor>


        <!--<acceptor name="in-vm">
            <factory-class>org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory</factory-class>
            <param key="server-id" value="0"/>
        </acceptor> -->

      </acceptors>

       

       

      My Client Program

       

      public static void main(String[] args) {
        try {
          QueueConnection queueConnection = null;
          QueueSession queueSession = null;
          try {
             long startTime = System.currentTimeMillis();
             final Context initialContext = new InitialContext(getJNDIProerties());
             QueueConnectionFactory connFactory = (QueueConnectionFactory) initialContext.lookup("/ConnectionFactory");
             logger.debug("{}", connFactory);
             Queue jmsQueue = (Queue) initialContext.lookup("/queue/AdrLoggerQueue");
             if(null != jmsQueue) {
                logger.debug("Got reference of a queue...");
             }
                 
             queueConnection = connFactory.createQueueConnection();
             queueSession = queueConnection.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
             logger.debug("Time taken to get connection and session --> {} {}", (System.currentTimeMillis() - startTime), "ms");
             MessageProducer producer = queueSession.createSender(jmsQueue);
                 
           } finally {
                  
               if(null != queueSession) {
                   queueSession.close();
               }
                  
               if(null != queueConnection) {
                   queueConnection.close();
               }
           }
        } catch(Exception e) {
            logger.error("Exception... ", e);
        }
      }

       

      private static Properties getJNDIProerties() {
              logger.debug("getJNDIProerties : START");
             
              final Properties jndiProperties = new Properties();
             
              jndiProperties.put(Context.PROVIDER_URL, "jnp://my.corp.com:1218");
              jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
              jndiProperties.put(Context.URL_PKG_PREFIXES, "java.naming.factory.url.pkgs");
             
              logger.debug("getJNDIProerties : END");
              return jndiProperties;
          }

       

      I am getting following exception for the statement "queueConnection =  connFactory.createQueueConnection();"

       

      2010-04-14 22:34:29,582 DEBUG [jms.JMSMessagePublishTest] - getJNDIProerties : START
      2010-04-14 22:34:29,582 DEBUG [jms.JMSMessagePublishTest] - getJNDIProerties : END
      2010-04-14 22:34:29,610 DEBUG [org.jnp.interfaces.TimedSocketFactory] - createSocket, hostAddr: my.corp.com/17.108.171.76, port: 1218, localAddr: null, localPort: 0, timeout: 0
      2010-04-14 22:34:30,082 DEBUG [jms.JMSMessagePublishTest] - org.hornetq.jms.client.HornetQConnectionFactory@e90943
      2010-04-14 22:34:30,170 DEBUG [jms.JMSMessagePublishTest] - Got reference of a queue...
      2010-04-14 22:34:30,369 ERROR [jms.JMSMessagePublishTest] - Exception...
      javax.jms.JMSException: Unable to connect to server using configuration org-hornetq-integration-transports-netty-NettyConnectorFactory?host=my-corp-com&port=4350
          at org.hornetq.core.client.impl.FailoverManagerImpl.createSession(FailoverManagerImpl.java:341)
          at org.hornetq.core.client.impl.ClientSessionFactoryImpl.createSessionInternal(ClientSessionFactoryImpl.java:1063)
          at org.hornetq.core.client.impl.ClientSessionFactoryImpl.createSession(ClientSessionFactoryImpl.java:790)
          at org.hornetq.jms.client.HornetQConnection.authorize(HornetQConnection.java:558)
          at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:602)
          at org.hornetq.jms.client.HornetQConnectionFactory.createQueueConnection(HornetQConnectionFactory.java:128)
          at org.hornetq.jms.client.HornetQConnectionFactory.createQueueConnection(HornetQConnectionFactory.java:123)
          at jms.JMSMessagePublishTest.main(JMSMessagePublishTest.java:58)
      Caused by: HornetQException[errorCode=2 message=Unable to connect to server using configuration org-hornetq-integration-transports-netty-NettyConnectorFactory?host=my-corp-com&port=4350]
          ... 8 more

        • 1. Re: Not able to connect to Remote HornetQ
          jmesnil

          NIranjan Nanda wrote:

           

          <connectors>
            <connector name="netty">
              <factory-class>org.hornetq.integration.transports.netty.NettyConnectorFactory</factory-class>
              <param key="host"  value="${jboss.bind.address}"/>
              <param key="port"  value="4085"/>
            </connector>


          </connectors>


          <acceptors>  
            <acceptor name="netty">
              <factory-class>org.hornetq.integration.transports.netty.NettyAcceptorFactory</factory-class>
              <param key="host"  value="${jboss.bind.address}"/>
              <param key="port"  value="4350"/>
            </acceptor>


          The connector must have defined the same port that the acceptor.
          see http://hornetq.blogspot.com/2009/10/understanding-connectors-acceptors.html for a complete explanation

          • 2. Re: Not able to connect to Remote HornetQ
            nnanda

            Hi Jeff,

             

            Thanks for the clarification. That did help resolving the issue.

             

            Now I am facing another strange issue. Strange, because I could not figure out what is the reason. The description is shown below:

             

            I have an MDB (EJB3) which is listening to the queue "MyQueue" configured in HornetQ. If I run the JBoss instance on my local machine and deploy the ADR, it is able to pick the messages, but on the configuration I explained in my previous discussion (HornetQ inside JBoss running on remote host), it is not picking up the messages. Could you please help me in this regard?

             

            The MDB:

             

            @MessageDriven (
              name = "LoggerMDB",
              description = "Puts the data in the DB log table from MyLoggerQueue",
              activationConfig = {
                  @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
                  @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/MyLoggerQueue")
              }
            )
            @ResourceAdapter("hornetq-ra.rar")
            @Interceptors(SpringBeanAutowiringInterceptor.class)
            public class DemoLoggerMDB implements MessageListener
            {
              
                /** For publishing log data in database */
                @Autowired
                private DatabaseLogPublisherImpl databaseLogPublisher;
               
                /**
                 * This is a call-back method and can be used to initialize all helper stuffs for this MDB
                 */
                @PostConstruct
                public void initializeResources() {
                    logger.debug("initializeResources : START");
                   
                    logger.debug("initializeResources : END");
                }
               
                /**
                 * This call-back method can be used to free any resources that this MDB uses.
                 */
                @PreDestroy
                public void cleanupResources() {
                    logger.debug("cleanupResources : START");
                   
                    logger.debug("cleanupResources : END");
                }
               
                /* (non-Javadoc)
                 * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
                 */
                public void onMessage(Message message) {
                    logger.debug("onMessage : START");
                   
                    if(message instanceof ObjectMessage) {
                        try {
                            final ObjectMessage receivedMessage = (ObjectMessage) message;
                            final Object receivedObject = receivedMessage.getObject();
                            if(receivedObject instanceof LogDTO) {
                                databaseLogPublisher.publishLog((LogDTO) receivedObject);
                            }
                        } catch(Exception e) {
                            // For any exception, let this publishing fail.
                            logger.debug("Exception while publishing log data... ", e);
                            logger.error("Exception while publishing log data... {}", e.getMessage());
                        }
                    }
                   
                    logger.debug("onMessage : END");
                }

             

            }

             

             

            Thanks,

            Niranjan