Preventing and Handling Duplicate Messages ON onMessage() method
Incidentally ,we found our MDB handling duplicate messages ,why does it happen?
from WLS online doc,I get the infos:
"If the MDB receives the message, but fails to send an acknowledgement, the JMS producer re-sends the same message ,even the onMessage() method successful completed
So ,If the MDB manages its own transactions, then your onMessage() code must be prepared to handle duplicate messages"
The resolve way is Using the CMT on MDB
1. Set the transaction-type element inside the message-driven element in the ejb-jar.xml file to Container.
2. Set the trans-attribute element inside the container-transaction attribute in the ejb-jar.xml file to Required.
This means message receipt and acknowledgement happen within a transaction; either both happen or neither happens.
Ok , it 's very simple, But in this way ,what's difference between the synchronous & asynchronous in this scenario, asynchronous in a big transaction is looks like a synchronous method with local trans, decouple a little?
IMHO,Customer will take a good think in this scenario
*******************************************************
another notes
when using the MDB ,you should take care the sender 's transaction setting ,when set the jmsConnectionFactory,Don't forget the UserTransactionsEnabled option,which means whether send method is JTA aware