On January 27th, this site will be read-only as we migrate to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 30th, when you will be able to use this site as normal.

    Forum Stats

  • 3,889,660 Users
  • 2,269,775 Discussions


How to send a JMS message to a remote Queue?

b7a Member Posts: 11 Blue Ribbon
edited Aug 22, 2011 10:37PM in Java Message Service (JMS)

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


  • 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.

  • 883902
    883902 Member Posts: 4

    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.
This discussion has been closed.