2
votes

This is my configuration:

@Bean
ActiveMQConnectionFactory activeMQConnectionFactory() {
    String url = this.environment.getProperty("jms.broker.url");
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
    connectionFactory.setBrokerURL(url);
    connectionFactory.setRedeliveryPolicy(redeliveryPolicy());
    return connectionFactory;
}

@Bean
public RedeliveryPolicy redeliveryPolicy() {
    RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
    redeliveryPolicy.setInitialRedeliveryDelay(500);
    redeliveryPolicy.setBackOffMultiplier(2);
    redeliveryPolicy.setUseExponentialBackOff(true);
    redeliveryPolicy.setMaximumRedeliveries(5);
    return redeliveryPolicy;
}
.....

And this is my consumer:

@Service("msgConsumer")
public class MessageConsumer {

    private static final String ORDER_RESPONSE_QUEUE = "thequeue.Q";

    @JmsListener(destination = ORDER_RESPONSE_QUEUE, containerFactory = "jmsListenerContainerFactory")
    public void receiveMessage(final Message<String> message) throws Exception {

        MessageHeaders headers =  message.getHeaders();
        LOG.info("Application : headers received : {}", headers);

        String response = message.getPayload();
        LOG.info("Application : response received : {}",response);

        if(response.equals("launch"))
            throw new Exception("Error");
    }
}

So i put in queue one message with payload = "launch".

I want to test the transaction and if payload equals "launch" it throw an Exception.

So thanks to the redeliverypolicy, the consumer try to consume the message for 5 times. After the fifth in ActiveMq queue list, I didn't see the message that I sent.

Where is placed the message? In a dead letter queue? Where I can see the dead letter queue with the "launch" message?

Thanks.

1

1 Answers

5
votes

ActiveMQ.DLQ - see the documentation here.

Once a message's redelivery attempts exceeds the maximumRedeliveries configured for the Redelivery Policy, a "Poison ACK" is sent back to the broker letting him know that the message was considered a poison pill. The Broker then takes the message and sends it to a Dead Letter Queue so that it can be analyzed later on.

The default Dead Letter Queue in ActiveMQ is called ActiveMQ.DLQ; all un-deliverable messages will get sent to this queue and this can be difficult to manage. So, you can set an individualDeadLetterStrategy in the destination policy map of the activemq.xml configuration file, which allows you to specify a specific dead letter queue prefix for a given queue or topic. You can apply this strategy using wild card if you like so that all queues get their own dead-letter queue, as is shown in the example below.

You can see the DLQ in the console; you can consume from it like any other queue.