Reputation: 99
I am trying to implement a strategy where when messages in an activemq queue expire, instead of being moved to the default dead letter queue ActiveMQ.DLQ, they will go another dead letter queue.
My application uses camel-context for routing and bean definition. I have looked at http://activemq.apache.org/message-redelivery-and-dlq-handling.html and I am not sure how to implement the individualDeadLetterStrategy.
I thought to try creating a Redelivery Policy bean and add that to my connection factory but I don't see a property for dead letter strategy here http://activemq.apache.org/redelivery-policy.html
I also considered using an error handler but my use case is not an error scenario.
My question is how do I configure/specify a dead-letter-queue for an individual queue.
I have configured my application to produce to the queue like this
<route id="myRoute">
<from uri="direct:insertToQueue" />
<doTry>
<bean ref="processorBean" method="getQueueRequest"/>
<to uri="activemqProducer:queue:myQueue" />
<doCatch>
<exception>java.lang.Exception</exception>
<handled>
<constant>true</constant>
</handled>
<bean method="getExceptionResponse" ref="processorBean" />
</doCatch>
</doTry>
</route>
the activemq component, "activemqProducer" is defined like this:
<bean id="activemqProducer" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="jmsConfigProducer"/>
</bean>
<bean id="jmsConfigProducer" class="org.apache.camel.component.jms.JmsConfiguration" scope="prototype">
<property name="connectionFactory" ref="jmsFactoryProducer"/>
<property name="transacted" value="false"/>
<property name="deliveryPersistent" value="true"/>
<property name="timeToLive" value="5000"/>
</bean>
<bean id="jmsFactoryProducer" class="org.apache.activemq.pool.PooledConnectionFactory"
init-method="start" destroy-method="stop" scope="prototype">
<property name="connectionFactory" ref="jmsConnectionFactory" />
<property name="maxConnections" value="${jms.maximum.connection}" />
<property name="maximumActiveSessionPerConnection" value="${jms.maximum.active}" />
</bean>
<bean id ="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL"><value>${message.broker}</value></property>
<property name="userName"><value>${message.broker.username}</value></property>
<property name="password"><value>${message.broker.password}</value></property>
<property name="optimizeAcknowledge" value="true"/>
<property name="useAsyncSend" value="true" />
</bean>
How can I include configurations for an individual dead letter queue for myQueue. If thats not possible, then how can I tell activemq to keep expired messages in myQueue
Upvotes: 3
Views: 5282
Reputation: 7005
The page you mention explains how to configure the DLQs in the broker configuration.
For example this configuration taken from the mentioned page configures the broker so that a non-deliverable message of a queue named MyMessageQueue
goes to DLQ.MyMessageQueue
instead of the standard ActiveMQ.DLQ
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry queue=">">
<deadLetterStrategy>
<individualDeadLetterStrategy queuePrefix="DLQ." useQueueForQueueMessages="true"/>
</deadLetterStrategy>
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
Probably not very clear is the destination wildcard queue=">"
that means "all queues". See this page for an explanation of these wildcards.
Due to the fact that destination configuration is done with help of these wildcards, it is advisable to name your queues and topics in a way that allows you "group" destinations with special configuration needs with such wildcards.
Upvotes: 1
Reputation: 3903
In the latest versions of ActiveMQ (eg Artemis), there is a way to define different expiry address (depending on regex on queue name):
<address-setting match="com.company.demo.MyQueue">
<expiry-address>com.company.demo.EXP.MyQueue</expiry-address>
</address-setting>
More info at: https://activemq.apache.org/artemis/docs/latest/message-expiry.html
Upvotes: 0