I have an MDB listener on an IBM MQ queue in IBM WAS server. MDB receives the message and do the processing and updates the database. These is one problematic scenario that I am unable to handle.
In case when a message arrived at MDB listener and it’s middle of processing, if someone forced stop the MDB application or restarts entire server note, the message under process will be lost from the queue without finishing the process. Is there any mechanism to avoid such scenario. I tries to use CLIENT_ACKNOWLEDGEMENT with message.acknowledge() but it didn’t work.
My MDB is like this:
@MessageDriven(name = "queueMDB", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
}
public class TestMdb implements MessageListener {
@Resource
private MessageDrivenContext messageDrivenContext;
@Override
public void onMessage(Message message) {
try {
// Some usefull code...
message.acknowledge()
}
catch (Exception e) {
messageDrivenContext.setRollbackOnly();
}
}
}
My ibm-ejb-jar.xml look like below:
<ejb-jar-bnd
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-bnd_1_2.xsd"
version="1.0">
<message-driven name="TestMdb">
<jca-adapter activation-spec-binding-name="jms/TestQueueAS" destination-binding-name="jms/TestQueue" />
</message-driven>
</ejb-jar-bnd>
Can anyone please help me solve this issue, If only I get the acknowledgement working, I will acknowledge every message, in case of forced stop, the queue message will not be acknowledged and will not be deleted from actual queue. That message will be processed once the MDB is up again.