0
votes

I have setting configuration in conf/activemq.xml about Redelivery and DLQ handling like this https://activemq.apache.org/message-redelivery-and-dlq-handling.html

But when I try to throw exception to see that will it work. It not work even send to default DLQ ActiveMQ.DLQ

@JmsListener(destination = "${queue-name}",
        concurrency="${queue-concurrency}",
        containerFactory="jmsListenerContainerFactory")
public void onMessage(TextMessage message) throws JMSException {

    try {

        LOG.debug("JMS Message = {}", message.getText());
        throw new Exception();

        // Do other thing.

    }
    catch (Exception e) {
        throw new JMSException(e.getMessage());
    }
1

1 Answers

0
votes

A dead-letter-queue is usually for messages that can't be delivered due to various factors (timeout, expiration, misconfiguration, etc.) - so there has to be a message that can't be delivered. In your case, however, the message was delivered ok, just not processed without exception.

If you want to bind the consumer's processing to the message, you should consider client acks or transactions. Then, if you don't ack or commit, because you had an exception before ack/commit, the message will repeatedly sent to your consumer - or sent to the DLQ.