Different dead

Given a basic MessageListener implementation which consumes messages from a RabbitMQ queue, how can I send the message to different dead-letter-queues based on the type of exceptions that could be thrown while processing it?

The queue were the messages are originally published has the x-dead-letter-exchange and x-dead-letter-routing-key set on it, but this is not enough in my case.

In case it matters, my application is using Spring 4 and Spring Amqp.


As far as I understand RabbitMQ documentation and Spring AMQP, it is not possible to send a message to different DLQs based on conditions from inside the code. The reason I say this is that my understanding from debugging the code is that when a message has to be send to a DLQ, the code doesn't specify the exchange or the routing key and RabbitMQ uses the ones defined when the message was published.

So, the only solution I found is to implement something like this:

try { try_to_do_useful_stuff(message); } catch (BusinessException e) { resend_the_message_to_business_dlq(message); }

This way, if a business exception is thrown, then the message is manually send to the business DLQ. Of course, some details get lost, like originating queue, but this is not an issue if they're not used.

When a non-business exception is thrown then the standard path is followed: retry (if configured) and then route to the defined DLQ.

链接地址: http://www.djcxy.com/p/59644.html

上一篇: 使用spring amqp模板清除rabbitmq队列?

下一篇: 不同的死亡