2 Replies Latest reply on Aug 23, 2011 2:37 AM by 883902

    How to send a JMS message to a remote Queue?


      I know how to create a JMS message and send it to an MDB that listens to a topic in the same container in which the JMS is created.

      In other words, if I have the following MDB:

      @MessageDriven(mappedName = "jms/MyQueue", ...)
      public class MyMDB implements MessageListener {
      // ...

      Elsewhere in my JEE app I can create a Queue like this:

      @Resource(mappedName = "jms/MyQueue")
      Queue queue;

      and use it to send a message to the MDB.

      But How can I send a message to an MDB that's deployed in another app server on another machine in the network? Both of the app servers are Glassfish.

      Thanks in advance.

      Edited by: EJP on 9/08/2011 21:49: fixed your meaningless title
        • 1. Re: How to send a JMS to a remote Queue?
          Nigel Deakin-Oracle
          Are the two GlassFish instances configured to be part of the same GlassFish cluster? If so then you don't need to do anything. MyQueue will work as a single queue for both instances.

          If the two GlassFish instances are NOT clustered then you have two separate queues, both with the JNDI name MyQueue. In this case you need to either

          1. Configure the sending application to send messages to the other instance
          2. Configure the MDB to receive messages from the other instance

          (obviously you must do one or the other, not both!).

          To define which instance a MDB receives messages from, set the activation config property connectionURL to point to the other instance. This will have the form mq://hostname:jmsport

          To define which instance an application sends messages to, set the connection factory property addressList to point to the other instance. Again, this will have the form mq://hostname:jmsport

          Don't forget that when you create the Queue object with JNDI name jms/MyQueue you need to define a property "Name" and set it to the actual name of the queue.

          • 2. Re: How to send a JMS message to a remote Queue?

            The first thing I would like to suggest is, we never/can't send message directly to MDB. We always send/receive message(s) to/from the destination. In case of MDB, the application server register the MDB as message listener against particular destination, and invoked the onMessage() method when message arrives on particular destination.

            If I am not wrong, what you want to achieve is asynchronous communication between two applications deployed in two different machine. In your case, you want your one application works as message producer and other act as an message consumer, and both are deployed in different machine.

            In this situations, you only need to configure the JMS administration object, connection factories and destinations, on one Application server and configure other application server to use those configuration using JMS resource adapter. you can well achieve this by configuring the JMS Resource Adapter. you need to check the Glassfish documentation.

            If you don't want to break the JMS specification, always communicate with Messaging Provider through Resource Adapter.

            I hope this helps.