问题
As a Operation guy (not a developer) and based on http://activemq.apache.org/message-redelivery-and-dlq-handling.html I have tried to set expiry time on the ActiveMQ.DLQ that is integrated into JBoss Fuse 6.2 to ensure that KahaDB's folder wont grow out of disk space but below settings seems do nothing on the queue messages but to copy them over to ActiveMQ.Advisory.Producer.Queue.ActiveMQ.DLQ twice.
...
<policyEntry queue=">" producerFlowControl="false">
<deadLetterStrategy>
<sharedDeadLetterStrategy expiration="300000"/>
</deadLetterStrategy>
</policyEntry>
...
To test this just sent messages into the ActiveMQ.DLQ queue using JBOSS FUSE MANAGEMENT CONSOLE and noticed a new queue is generated having double the number of messages that I had sent Enqueued:
ActiveMQ.Advisory.Producer.Queue.ActiveMQ.DLQ 0 0 0 8 0 0
ActiveMQ.DLQ 4 0 0 4 0 0
Any thought on this?
回答1:
Your deadLetterStrategy
is good and must work fine but you cannot test this like this because the expiration is set by the business code who try to deliver to a consumer and when it fails it sends the message to the DLQ by changing their expiration.
you can test by sending a message to any queue you want by setting the setJMSExpiration
(Time to live) to 1 for example, like this the message will not be delivered and sent directly to the DLQ if processExpired="true"
.
ActiveMQ.Advisory.Producer.Queue.ActiveMQ.DLQ
is created because you had a producer who's sent messages to ActiveMQ.DLQ
.
Because you have sent 4 messages to ActiveMQ.DLQ
you had 8 messages in ActiveMQ.Advisory.Producer.Queue.ActiveMQ.DLQ
because this topic receive a message when a producer start & another one when it stop messages, this means that your JBOSS FUSE MANAGEMENT CONSOLE creates a connection for sending a message and stops it after that.
Note that by default, ActiveMQ will never expire messages sent to the DLQ, if you want to keep them 7 days you can set <sharedDeadLetterStrategy expiration="604800000" processExpired="true" processNonPersistent="true" />
http://activemq.apache.org/advisory-message.html
http://activemq.apache.org/message-redelivery-and-dlq-handling.html
回答2:
The default action for an expired message is, to send it to the DLQ. You need to avoid processing of expired messages, which means: discard them. Adding processExpired="false"
on your DLQ should fix the issue.
(Quote from http://activemq.apache.org/message-redelivery-and-dlq-handling.html)
To tell ActiveMQ to just discard expired messages, configure the processExpired property to false on a dead letter strategy:
<broker...>
<destinationPolicy>
<policyMap>
<policyEntries>
<!-- Set the following policy on all queues using the '>' wildcard -->
<policyEntry queue=">">
<!--
Tell the dead letter strategy not to process expired messages
so that they will just be discarded instead of being sent to
the DLQ
-->
<deadLetterStrategy>
<sharedDeadLetterStrategy processExpired="false" />
</deadLetterStrategy>
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
...
</broker>
来源:https://stackoverflow.com/questions/40231077/how-to-set-expiry-for-activemq-dlq-queue