It is a rather simple question... I have a spring project where I consume queues (CONSUMER). Now I want to configure individual dead letter queues for each queue I am consuming.
However, in my mind, the individual dead letter queues configuration must be done in the broker service (SERVER), not in the CONSUMER. Is it really so?
My code below WILL NOT work, correct?
@Bean public DeadLetterStrategy deadLetterStrategy(){ IndividualDeadLetterStrategy dlq = new IndividualDeadLetterStrategy(); dlq.setQueueSuffix(".DLQ"); dlq.setUseQueueForQueueMessages(true); return dlq; } @Bean public ActiveMQConnectionFactory consumerActiveMQConnectionFactory() { var activeMQConnectionFactory = new ActiveMQConnectionFactory(); activeMQConnectionFactory.setBrokerURL(brokerUrl); RedeliveryPolicy policy = activeMQConnectionFactory.getRedeliveryPolicy(); policy.setMaximumRedeliveries(maximumRedeliveries); policy.setInitialRedeliveryDelay(0); policy.setBackOffMultiplier(3); policy.setUseExponentialBackOff(true); return activeMQConnectionFactory; } @Bean public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() { var factory = new DefaultJmsListenerContainerFactory(); factory.setSessionAcknowledgeMode(JmsProperties.AcknowledgeMode.CLIENT.getMode()); factory.setConcurrency(factoryConcurrency); factory.setConnectionFactory(consumerActiveMQConnectionFactory()); return factory; } @Bean public BrokerService broker() throws Exception { final BrokerService broker = new BrokerService(); broker.addConnector(brokerUrl); broker.setPersistent(false); broker.setDestinationPolicy(policyMap()); return broker; } @Bean public PolicyMap policyMap() { PolicyMap destinationPolicy = new PolicyMap(); List<PolicyEntry> entries = new ArrayList<PolicyEntry>(); PolicyEntry queueEntry = new PolicyEntry(); queueEntry.setQueue(">"); // In activemq '>' does the same thing as '*' does in other languages queueEntry.setDeadLetterStrategy(deadLetterStrategy()); entries.add(queueEntry); destinationPolicy.setPolicyEntries(entries); return destinationPolicy; } }
@JmsListener(destination = "myqueue")
public void onMessage(Message message, Session session) throws JMSException {
try {
stuff()
message.acknowledge();
} catch (Exception ex) {
session.recover();
}
}