Message Delivery Order on MDB Rollback (Cancel)
jmihalich1 Oct 5, 2010 6:21 PMHi,
I saw a few topics on this through search, but none really addressed the issue I'm seeing.
I am trying to test the message order functionality, because I don't see any type of behavior documented in the docs.
My test case is this:
- I have a JMS topic, with 2 consumers (both MDB's with durable subscriptions). We're running in Jboss 4.2.3, in EJB 2.1 land, CMT.
- MDB1 is coded to just receive and log each message it gets and return.
- MDB2 is coded to setRollbackOnly the first time it ever receives a message, and then for every subsequent call will receive, and log the message successfully and return like MDB1 does.
- I published 4 messages to the topic from a client that is external to the app server (publishing code is below), to the topic, through JNDI lookup. We'll call these messages MSG1, MSG2, MSG3, MSG4, and they are published in that order.
- I have redelivery delay set to <redelivery-delay>10000</redelivery-delay> 10 seconds.
- I am not using message grouping.
I ran this test 3 times:
My Results:
Test Run 1:
1) MDB1 got the msgs in order: MSG1, MSG2, MSG3, MSG4
2) MDB2 got MSG1 and rolled back the transaction. Then 10 seconds later, MSG4 came in. Immediately following I received MSG3, MSG2, and then MSG1 in that order.
Test Run 2:
1) MDB1 got the msgs in order: MSG1, MSG2, MSG3, MSG4
2) MDB2 got MSG1 and rolled back the transaction. Then 10 seconds later, MSG2 came in. Immediately following I received MSG4, MSG3, and then MSG1 in that order.
Test Run 3:
1) MDB1 got the msgs in order: MSG1, MSG2, MSG3, MSG4
2) MDB2 got MSG1 and rolled back the transaction. Then 10 seconds later, MSG4 came in. Immediately following I received MSG2, MSG3, and then MSG1 in that order.
So, I have some questions:
1) I thought the redelivery delay was only applied to the message that failed. Why are NO messages being redelivered for 10 seconds?
I have since run a slightly different test to try and see what was going on here. In this second test case, I published 2 messages (MSG1, MSG2), closed the JMS session, opened a new session, and published 2 more messages (MSG3, and MSG4). When I did this, MDB2 got MSG1 and rolled back. But a second later (roughly) in this case, MDB2 got MSG3 and MSG4. Then 10 seconds after MSG1 came in, I got: MSG2, then MSG1 came in again.
Why are we seeing different behavior here?
2) I would be expecting MDB2 to get messages in the following order: MSG1 (fail), MSG2, MSG3, MSG4, after 10 seconds MSG1 (succeed). Why are all the messages after MSG1 coming in, in what seems like a random order?
I understand this is perhaps irrelevant, but JBoss Messaging 1.4.x, and Websphere MQ work the way i described above where everything comes in, in the order published, following the failed message. Also, the jboss-messaging redelivery delay only applied to the failed message. messages behind the failed message were delivered immediately.
I also understand things get complicated if multiple messages start rolling back. But in this simple case, I'd expect messages to be in order after the first one failed.
hornetq config file is attached.
Here is the code I used to publish for an external client:
InitialContext ctx = getContext(mqProviderType, providerUrl);
TopicConnectionFactory factory = (TopicConnectionFactory)ctx.lookup(connectionFactory);
Topic topic = (Topic)ctx.lookup(topicName);
connection = factory.createTopicConnection();
session = ((TopicConnection)connection).createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
publisher = ((TopicSession)session).createPublisher(topic);
for (int index=0; index < messages.length; index++)
{
Message message = messages[index];
TextMessage textMessage = session.createTextMessage();
populateTextMessage(message, textMessage);
publisher.publish(textMessage);
}
Thanks for the help.
Joe