7 Replies Latest reply on Oct 16, 2006 7:49 PM by Ovidiu Feodorov

    JBoss Messaging server cannot connect to Remote Messaging Cl

    Terry Paterson Newbie

      Hi There,

      Using JBoss 4.0.4GA-Patch1, and JBoss messaging 1.0.1.CR5,

      We have taken one of the examples from the jboss-messaging-1.0.1.CR5 zip file (examples/mdb/..../Sender.java) and modified it slightly - in order to connect to a remote JBoss server (simply passing a Hashtable of JNDI properties to the InitialContext constructor)..

      This appears to work in that the client can connect to a queue on the server and listen for messages -- but no messages ever arrive (we have successfully put messages into the queue from the local machine). Instead, we just see log messages every 5 seconds saying that no message was received.

      After turning up the debugging on the server side we can see the following :

      15:39:25,875 TRACE [MicroSocketClientInvoker] Creating socket number 31
      15:39:26,796 DEBUG [MicroSocketClientInvoker] java.net.ConnectException: Connection refused: connect

      15:39:26,812 TRACE [MicroSocketClientInvoker] Creating socket number 32
      15:39:27,890 DEBUG [MicroSocketClientInvoker] java.net.ConnectException: Connection refused: connect

      15:39:27,906 TRACE [MicroSocketClientInvoker] Creating socket number 33
      15:39:28,984 DEBUG [MicroSocketClientInvoker] java.net.ConnectException: Connection refused: connect

      15:39:29,000 TRACE [MicroSocketClientInvoker] Creating socket number 34
      15:39:30,078 DEBUG [MicroSocketClientInvoker] java.net.ConnectException: Connection refused: connect

      15:39:30,093 TRACE [MicroSocketClientInvoker] Creating socket number 35
      15:39:31,171 DEBUG [MicroSocketClientInvoker] java.net.ConnectException: Connection refused: connect

      The modified version of Sender.java is:import javax.jms.Connection;
      import javax.jms.ConnectionFactory;
      import javax.jms.JMSException;
      import javax.jms.Message;
      import javax.jms.MessageConsumer;
      import javax.jms.Queue;
      import javax.jms.Session;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import java.util.Hashtable;

      /**
      * Simple test program to receive 1000 messages and time it.
      */
      public class ReceiveTestMessages {

      public static void main(String[] args) throws NamingException, JMSException {
      String destinationName = "queue/testQueue";

      Hashtable props = new Hashtable();

      props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
      props.put("java.naming.provider.url", "jnp://192.168.1.253");
      props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");

      InitialContext ic = new InitialContext(props);

      ConnectionFactory cf = (ConnectionFactory) ic.lookup("/ConnectionFactory");
      Queue queue = (Queue) ic.lookup(destinationName);

      log("Queue " + destinationName + " exists");

      Connection connection = cf.createConnection();
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

      MessageConsumer consumer = session.createConsumer(queue);

      connection.start();

      int messageCount = 0;
      long firstMessageRcvd = -1;

      log("Waiting for messages...");

      while (messageCount < 1000) {
      Message message = consumer.receive(50000);
      if (message == null) {
      log("No message");
      continue;
      }
      messageCount++;

      log("Received message: #" + messageCount);

      if (firstMessageRcvd == -1) {
      firstMessageRcvd = System.currentTimeMillis();
      }

      if (messageCount == 1000) {
      long delta = System.currentTimeMillis() - firstMessageRcvd;
      log("received 1000 messages in " + delta + " ms");
      firstMessageRcvd = -1;
      //messageCount = 0;
      }


      }

      connection.close();
      }

      private static void log(String s) {
      System.out.println(s);
      }

      }

      The code works when run on the local machine.

      We have also changed the hostname in the jndi.properties file in the mdb example, and this also works locally but fails across the network. However, we do not see the "connection refused" messages in the server log in this case (possibly the server had already put closed connections into the socket pool somehow on the previous test?).

      Is there anything that needs to be set up on the client machine in order to allow it to receive messages?