users@glassfish.java.net

Re: Possibilities to configure JMS in Glassfish. Problem ...

From: Nigel Deakin <nigel.deakin_at_oracle.com>
Date: Fri, 16 Dec 2011 10:56:47 +0000

> Three step task managment.
>
> 1. Manager send something like that: "I have a job, who want to take this
> job", and publish this message to "jms/discoveryTopic"
>
> 2. Workers (instance 2 and 3 in this example ) decides to answer and publish
> a message to "jms/offerTopic"
>
> 3. Manager is waiting for offers and after a while chose one worker to
> execute job.

Why would the manager choose one "worker" over another? Do you mean that you want to choose at runtime which particular
GlassFish instance processes a particular message?

The normal technique when sending messages which represent unique pieces of work is

1. To send work messages to a queue, not a topic (since you only want each piece of work to be handled once)
2. To configure a cluster of GlassFish instances and deploy a MDB which consumes messages from that queue.

When your sending application sends work messages to the queue, it needs to create a connection to one of the instances
in the cluster. To avoid unnecessary network hops this will give priority to a MDB instance running on the same
instance, but if workload is high it will forward messages to other instances instead.

This might sounds a bit uneven. However if your sending application is, say, a session bean it will select a connection
from a pool of available connections, use it to send the message, and then return the connection to the pool. If you
want, you can configure the connection pool so that each randomly chooses which instance to connect to. That means that
you will be spreading the load more evenly.

To do this, configure the sending applications's connection factory's addressList property to be a comma-separated list
containing all the instances in the cluster. Something like
mq://hostname1:1234/jms,mq://hostname2:1235/jms, mq://hostname3:1236/jms
also set the addressListBehavior property to RANDOM
(see http://docs.oracle.com/cd/E18930_01/html/821-2438/aeoop.html)

>
> Thank you Nigel for your advice, but now Manager is on the cluster, not on
> server, and when I send a task via Instance1, only worker on Instance1 can
> recieve a message.

If instance 1 is part of a cluster, then a message sent to the topic may be delivered to a MDB on any of the instances
in the cluster. You may need to increase the throughput to see this - if the throughput is low then instance1 will be
able to handle all the messages quickly enough and there is no need for instance1 to share the load with the other
instances.

> Do I really need to install and configure standalone broker ?

No.

Nigel