users@glassfish.java.net

Problem with topic MDB in a cluster env

From: <glassfish_at_javadesktop.org>
Date: Tue, 29 Apr 2008 15:24:20 PDT

We have configured a cluster with 2 instances on 2 hosts with Glassfish V2b58g, both instances are REMOTE to the stand alone master JMS server running with the Sun openMQ 4.0 (also set up in master/cluster).

Here is what we trying to do:

1.process program logic in asynchronous/parallel fashion using MDB with queue
2.after finish all the process, send a message to all instances using MDB with topic

The item 1 is function well, when multiple messages sending to the queue, there are MDB started on all instances.

How ever the item 2 has problem, when all process are done (some kind of tracking in the database) the last MDB will publish a message (invoke a session bean). I was expecting that the topic message will be published to all instances, but in real scenario always only one instance ever getting the message. Even if the message is sent from instance 1, it may end up in instance 2. (if it is not specified, should the topic message by default be none durable ?)

Using the imqadmin, I can see the queue destination has 2 consumers, but the topic destination always only have 1 consumer.

Then I tried to use the local JMS server from the DAS instead of the stand alone server, the same behavior occurred.

I am not sure is there any additional configuration or code is needed to make the topic destination have multiple consumers. Please help.

The sample code is attached here:


on the publisher side (a session bean)

@Resource(mappedName = "jms/TopicConnectionFactory")
 private TopicConnectionFactory topicConnectionFactory;
    
@Resource(mappedName = "jms/TaskScheduleTopic")
 private Topic scheduleTopic;

...

        TopicConnection connection = null;
        TopicSession session = null;
        MyMessage msg = null;

        // prepare msg here
        
        try {
            connection = topicConnectionFactory.createTopicConnection();
            session = connection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
            TopicPublisher messageProducer = session.createPublisher(scheduleTopic);
            messageProducer.publish(session.createObjectMessage(msg));
        } catch (Throwable ex) {
            log.severe("Exception caught while sending topic to MDB: ", ex);
        } finally {
            if (session != null) {
                try {
                    session.close();
                } catch (JMSException ex) {
                    ex.printStackTrace();
                }
            }
            if (connection != null) {
                try {
                    connection.close();
                } catch (JMSException ex) {
                    ex.printStackTrace();
                }
            }
        }

The MDB:


@MessageDriven(mappedName = "jms/TaskScheduleTopic", activationConfig = {
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic")
})
public class TaskScheduleMDB implements MessageListener {

    Logger log = Logger.getLogger(TaskScheduleMDB.class.getName());

    public TaskScheduleMDB() {
        // nothing
    }

    /**
     *
     * @param message
     */
    public void onMessage(Message message) {
        ObjectMessage msg = (ObjectMessage) message;
        MyMessage taskMsg = (MyMessage) msg.getObject();

        // program logic here

    }
}
[Message sent by forum member 'evanyang168' (evanyang168)]

http://forums.java.net/jive/thread.jspa?messageID=272130