0 Replies Latest reply on Aug 23, 2011 2:08 AM by urug

    JBoss AS7 JMS queue:  sending message from remote client

    urug

      Hi,

       

      I have been reading numerous articles on how to do this but seem to have run into a wall. My setup is as follows - Two JBoss AS7 standalone servers, A and B. The standalone-preview.xml of 'A' has the following entries in the JMS subsystem section -

      ...

      <jms-connection-factories>

      ...

          <connection-factory name="RemoteConnectionFactory">

              <connectors>

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

              </connectors>

              <entries>

                  <entry name="RemoteConnectionFactory"/>

              </entries>

      ...

      </jms-connection-factories>

      <jms-destinations>

          <jms-queue name="testQueue>

              <entry name="queue/testQueue"/>

          </jms-queue>

      ....

      </jms-destinations>

       

      I initially had a publisher and listener (MDB) within the same JBoss instance - 'A' to test out my implementation. Everything worked flawlessly - messages published to the queue were automatically received by the MDB and acted upon. Then I tried to move the publisher to JBoss AS7 instance 'B', which is where all the problems started. I cannot seem to receive the message on 'A' that was sent by the publisher on 'B'. I am assuming it has something to do with how I am looking up JNDI and/or possibly whether the queue/connection factory above is published to the global name space.

       

      Both 'A' and 'B' AS7 instances have the same copy of standalone-preview.xml, with the only difference being the individual IP addresses configured in there.

       

      The publisher code looks as follows -

         

      public Context getRemoteContext()             throws javax.naming.NamingException     
      {         
           Properties properties = new Properties();
           properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory");         
           properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");        
            // TODO: Replace by  IP of 'A' dynamically         
           properties.put(Context.PROVIDER_URL, "jnp://192.168.110.155:1099");        
            try         
           {             
                return new javax.naming.InitialContext(properties);        
            }         
           catch (NamingException e)        
            {             
                log.errorf(e, "Unable to obtain initial context. Caught exception: " + e.toString());             
                throw e;         
           }     
      }      
      
      @PostConstruct     
      public void initJmsConnection()             throws JMSException, NamingException     
      {         
           log.infov("Opening JMS connection to A...");         
           final InitialContext initialContext = (InitialContext) getRemoteContext();         
           ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup("java:/RemoteConnectionFactory");         
           Queue agentQueue = (Queue) initialContext.lookup("java:queue/testQueue");         
           connection = connectionFactory.createConnection();         
           session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);         
           producer = session.createProducer(agentQueue);         ]
           log.infov("Established JMS connection to controller");     
      }      
      
      public void publishMessage(MyMessage registerMessage)             throws JMSException    
      {         
           log.infov("Publishing register message {0}", registerMessage);         
           ObjectMessage msg = session.createObjectMessage(registerMessage);        
            producer.send(msg);     
      }      
      
      @PreDestroy     public void closeJmsConnection()             throws JMSException     
      {         
           log.infov("Closing JMS connection to controller");         
           session.close();         
           connection.close();     
      }
      

       

      Object lookup works but no messages are received by 'A'. I think this is because it resolves the connection factory and queues of the local ('B') AS7 instance. As soon as I change the connection factory / queue entry names on AS7 'A', object lookup fails as well.

       

      What am I doing wrong? I read somewhere that the 'java;' JNDI context is within a JVM...is that the problem? How do I publish to the global JNDI namespace?

       

      Help much appreciated.

       

      Thanks