I have an application which uses the DLQ for messages which have been
redelivered a certain number of times.
All goes well when the consumer calls rollback(), since the consumer has
the opportunity to send back a poisoned ack, and this gets handled well.
However there are situations where some messages can cause the entire
JVM to exit abnormally in my application. In this situation, if the
message has been redelivered enough, I'd like the message to go the the
DLQ as well in the same way.
The current code however will prevent this from occurring. Below is a
very rough patch to PrefetchSubscription.remove(ConnectionContext
context, Destination destination) to use the sendToDLQ() method?
I have run out of time today to test this (I originally had these
changes in Queue) - but would love some feedback from the activemq
developers on this. I know 6 is hardwired in the code - I couldn't see
an easy way to get the DLQ policy..
Without this change, this "poison message" which kills my consumer JVM
just keeps getting resent forever..
Index:
activemq-core/src/main/java/org/apache/activemq/broker/region/PrefetchSubscription.java
===================================================================
---
activemq-core/src/main/java/org/apache/activemq/broker/region/PrefetchSubscription.java
(revision 739923)
+++
activemq-core/src/main/java/org/apache/activemq/broker/region/PrefetchSubscription.java
Mon Mar 16 17:21:02 EST 2009
@@ -541,10 +541,19 @@
synchronized(dispatchLock) {
for (MessageReference r : dispatched) {
if( r.getRegionDestination() == destination) {
+ // Its possible this message caused the
consumer to abnormally terminate.
+ // Check if it should be moved to the DLQ.
+ if (r.getRedeliveryCounter() >= 6)
+ {
+ sendToDLQ(context, r);
+ }
+ else
+ {
- rc.add((QueueMessageReference)r);
- }
- }
- }
+ rc.add((QueueMessageReference)r);
+ }
+ }
+ }
+ }
// TODO Dispatched messages should be decremented from
Inflight stat
// Here is a potential problem concerning Inflight stat:
// Messages not already committed or rolled back may not
be removed from dispatched list at the moment
--
Cheers,
David
Nuix Pty Ltd
Suite 79, 89 Jones St, Ultimo NSW 2007, Australia Ph: +61 2 9280 0699
Web: http://www.nuix.com Fax: +61 2 9212 6902