Example 4: Automatically stopping an MDB when no exception destination is specified
To prepare for a system resource becoming unavailable or a problem message, configure the system to stop the message-driven bean (MDB) automatically. To maintain message ordering, do not use an exception destination.
Before you begin
The destination to which the MDB listens must not use an exception destination, that is, the exception destination for the queue or topic space destination must be configured as none.
- The enterprise application that contains the MDB.
- The dependent external system resources.
- A value of 1 for the Sequential failed message threshold. This is the maximum number of sequential failures of delivery of messages, after
which the MDB is stopped. This property applies to sets of messages.Note: If this property is set to a value greater than 1, the system automatically resets it to 1 when an exception destination is configured as none.
- A value of 5000 for the Delay between failing message retries, that is, the time in milliseconds before a failing message is available to be delivered to the MDB. Other messages might be delivered during this period, unless theSequential failed message threshold and the maximum concurrency is set to 1.
- An acceptable value for the Maximum failed deliveries per message, that is, the maximum number of failed attempts to process a message. This property applies to individual messages.
The JCA MBean emits JMX notifications to indicate that the MDB is paused, and that the MDB has resumed. Consider registering a message listener on the JCA MBean to receive the JMX notifications.
About this task
In this scenario, the enterprise application is a continuously running system that uses a deployed MDB to access an external system resource.
When a problem message (msg1 in this scenario) is encountered, it is put back on the queue.
Instead of msg1 being made available to the MDB immediately, it is hidden for the Delay between failing message retries retry delay (five seconds in this scenario).
When the number of hidden messages reaches the Sequential failed message threshold, the MDB will not process any further messages until one of the hidden messages becomes re-available. In this scenario, this threshold is reached as soon as msg1 is hidden.
When the Delay between failing message retries for msg1 expires, msg1 is unhidden and reprocessed.
This process is repeated until msg1 reaches its Maximum failed deliveries per message limit (five times in this scenario).
After msg1 is unhidden for the fourth time, rolled back and rehidden, the Sequential failed message threshold is reached and the MDB stops automatically. A JMX notification is emitted by the JCA MBean and a log entry alerts the system administrator that the MDB has stopped.