I have MQ as an external JMS server on my Weblogic server. The thing is that I need to rollback the message and retry until backout threshold is reached. Then I need to move the message to backout queue.
The MessageDrivenContext.setRollbackOnly() method takes care of that just fine. The problem, however, is with the message on the backout queue - it is uncommited.
Moreover, the messages are being taken from backout queue and processed again as soon as new message appears on the main queue.
This suggest me that there is something teribly wrong with my approach. I cannot, however, change the fact, that I have to retry the onMessage() with the same message a couple of times and send it to backout queue is backout threshold was reached.
@MessageDriven( name="MQListener", mappedName = "jms.mq.SOME.QUEUE.NAME",
activationConfig =
{
@ActivationConfigProperty(propertyName = "destinationType",propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "jms.mq.SOME.QUEUE.NAME"),
@ActivationConfigProperty(propertyName = "connectionFactoryJndiName", propertyValue = "jms.mq.MQ"),
@ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "true")
})
public class MQListener implements MessageListener {
@Resource
private MessageDrivenContext context;
@Override
public void onMessage(Message message) {
String messageContent="";
try {
messageId = message.getJMSMessageID();
if (message != null) {
messageContent = ((TextMessage)message).getText();
if(!doSomething(messageContent)){
// doSomething fails, I need to rollback the message and try again:
context.setRollbackOnly();
}
}
} catch (Exception e) {
throw new RuntimeException();
}
}
private boolean doSomething(String messageContent){
// ...
}
}