users@glassfish.java.net

Re: How to configure JMS in cluster mode where messages produced and consumed on the same node

From: Nigel Deakin <nigel.deakin_at_oracle.com>
Date: Fri, 27 Aug 2010 14:22:28 +0100

Saikiran,

saikiranp wrote, on 27/08/2010 12:25:
>
> Hi All,
> I have setup sailfin in cluster (my-cluster) mode as below.
>
> machine 1 : my-domain, agent1, instance1
> machine 2 : agent2, instance 2
>
> I have create a queue "MyQueue" and its corresponding resources by using the
> following command.
>
> create-jmsdest --desttype queue --target my-cluster MyQueue
> create-jms-resource --target my-cluster --restype
> javax.jms.QueueConnectionFactory jms/MyQcf
> create-jms-resource --target my-cluster --restype javax.jms.Queue --property
> imqDestinationName=MyQueue jms/MyQueue
>
> So the configurations if the JMS Service looks as follows.
>
> Type: LOCAL
> Address List Behavior: Priority
>
> I created on MDB listener and deployed it on the cluster. When i send some
> 10 message to the queue , some are delivered to listener on instance-1 and
> some other are delivered to listener on instance-2.
>
> i mean 1, 3, 7, 8& 10 are delivered on instance 1 and 2, 4, 5, 6& 9 are
> delivered on instance-2.

Yes, this is as I would expect. The two brokers are clustered and so messages on the queue may be consumed by consumers
connected to either broker.
>
> But as per the Sun GlassFish Enterprise Server 2.1 Developer's Guide , if i
> set the behaviour as priority and type as local, it should behave as "This
> ensures colocated production and consumption of messages and equitable load
> distribution across the Message Queue broker cluster".
>
> But my test shows that it is not behaving as specified in the document.

When you configure the JMS Service to be "LOCAL", when you start a Glassfish instance this automatically starts a MQ
broker process running on the same machine. Here, LOCAL means co-located.

In your installation this means you will have (ignoring the domain and node agents):

> machine 1 : instance1, broker1
> machine 2 : instance 2, broker2

The section in the user guide that you refer to is describing how to ensure that JMS connections from instance1 will
connect to broker1 (the "clocated broker") and JMS connections from instance2 will connect to broker2.

However the two brokers are be connected in a cluster, so that consumers connected to one broker can receive messages
from producers connected to the other broker. So messages are delivered to MDBs in both instances.

> How can i configure it, so that the messages will be consumed on the same
> node where i am producing the messages?

You've configured Glassfish to be clustered, which means that the two instances will behave as if they were one, with
the load of processing messages spread between the two. If you don't want them to share the load, then don't put them in
the same cluster.

Nigel