users@glassfish.java.net

Message Driven Bean receives messages at the same time, transaction

From: <glassfish_at_javadesktop.org>
Date: Mon, 03 May 2010 05:32:44 PDT

Hello all!

We have a Message Driven Bean which listens on a jms queue and receives 3 messages fired by one test at the same time.
MDB has annotation @TransactionAttribute(TransactionAttributeType.REQUIRED). So if i understand correctly it means that the messages must be proceed in a sequence because of a queue and transaction attribute.

Here is simpified MDB code exampe:

@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class TestCommMDB implements MessageListener {
        private static final Logger LOGGER = LoggerFactory.getLogger(TestCommMDB.class);

        public TestCommMDB(){}
        
        public void onMessage(Message message) {
                LOGGER.debug("onMessage(), START: onMessage()... ------------------------------------------------------------------------------");
                
                try {
                        if (message instanceof ObjectMessage) {
                                ObjectMessage objMessage = (ObjectMessage) message;
                                Serializable msgObject = objMessage.getObject();
                                
                                if (msgObject instanceof Response) {
                                        Response response = (Response) msgObject;
                                        LOGGER.debug("Response: " + response.toString());
                                }
                        
                        }
                } catch (Exception ex) {
                        throw new RuntimeException("Unexpected RuntimeException occurs.", ex);
                }

                try {
                        Thread.sleep(5000);
                } catch (InterruptedException e) {
                        e.printStackTrace();
                }
                
                LOGGER.debug("END: onMessage()...");


But the messages are proceed in parallel. The second transaction begins at the same time as first, but the first was not ended.
Here the log file for this case:

2010-05-03 13:42:05,588 DEBUG TestCommMDB :63] NDC4=: onMessage(), START: onMessage()... ------------------------------------------------------------------------------
2010-05-03 13:42:05,588 DEBUG TestCommMDB :72] NDC4=: Response: Response[resultCode=0, result=Response.SIGNAL_SUCCESS, sessionID=]
2010-05-03 13:42:05,588 DEBUG TestCommMDB :63] NDC5=: onMessage(), START: onMessage()... ------------------------------------------------------------------------------
2010-05-03 13:42:05,588 DEBUG TestCommMDB :72] NDC5=: Response: Response[resultCode=1, result=Response.SIGNAL_BACKEND_ERROR, sessionID=]
2010-05-03 13:42:05,588 DEBUG TestCommMDB :63] NDC6=: onMessage(), START: onMessage()... ------------------------------------------------------------------------------
2010-05-03 13:42:05,604 DEBUG TestCommMDB :72] NDC6=: Response: Response[resultCode=4, result=Response.SIGNAL_SESSION_INVALID, sessionID=]
2010-05-03 13:42:10,588 DEBUG TestCommMDB :89] NDC4=: END: onMessage()...
2010-05-03 13:42:10,588 DEBUG TestCommMDB :89] NDC5=: END: onMessage()...
2010-05-03 13:42:10,604 DEBUG TestCommMDB :89] NDC6=: END: onMessage()...

What can be a problem?
Thanks!
[Message sent by forum member 'phoenixtern']

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