2

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.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
michele
  • 26,348
  • 30
  • 111
  • 168

1 Answers1

5

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.

Community
  • 1
  • 1
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • so if I have a queue called "myqueue.Q" what is the correct name for the DLQ? – michele Jan 26 '18 at 13:46
  • Read the documentation I pointed you to `ActiveMQ.DLQ`. Everything goes to the same DLQ by default. `>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. ` – Gary Russell Jan 26 '18 at 16:53
  • dumb question: the DLQ configuration in activemq.xml is made in the server, not in the client, correct? – guilhermecgs Nov 05 '20 at 15:51
  • @guilhermecgs Yes, on the ActiveMQ server. – cmoetzing Mar 21 '22 at 11:48