How to Configure MDB Message Redelivery When onMessage() Returns a Failure? (Doc ID 1054218.1)

Last updated on NOVEMBER 05, 2016

Applies to:

Oracle Containers for J2EE - Version: 10.1.3.1.0 and later   [Release: AS10gR3 and later ]
Information in this document applies to any platform.

Goal

Having a CMT message-driven bean, a J2EE application is deployed into 10.1.3 OC4J.
If an error is detected in the onMessage(), the application rolls backs the transaction (by calling   setRollbackOnly() method , or throws an ApplicationException message) :

@TransactionManagement(value=TransactionManagementType.CONTAINER)

public class TestMessageDrivenEJBBean implements MessageListener,MessageDrivenBean {
@Resource
private MessageDrivenContext context;

public void setMessageDrivenContext(MessageDrivenContext icontext) throws EJBException {
context = icontext;
}

public void ejbCreate() { }

@TransactionAttribute(value=javax.ejb.TransactionAttributeType.REQUIRED)

public void onMessage(Message message) {
// ... normal message handling code
if (error ) {
context.setRollbackOnly();
// ... error handling code
}

}
public void ejbRemove() {
}
}

In this case (transaction is rollback), after the onMessage() treatment, the message will be left in the JMS destination. And, OC4J will try automatically to re-deliver the message by re-calling the onMessage() method again.

This note demos how a message-driven bean can be configured to make OC4J re-attempt to deliver the message x number of times.


Solution

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms