拒绝消息时设置x-first-death-reason或自定义标头(SpringAMQP)

时间:2018-04-27 04:19:10

标签: spring spring-boot spring-amqp

我有SpringBoot AMQP应用程序,我为队列设置了死信。无论如何都要在抛出AmqpRejectAndDontRequeueException

时为x-first-death-reason设置自定义消息

我现在有这个

@RabbitListener(bindings = @QueueBinding(
    value = @Queue(value = "core.queue",
                durable = "true",
                arguments = {
                    @Argument(name = "x-dead-letter-exchange", value = RabbitConfiguration.ERROR_EXCHANGE),
                    @Argument(name = "x-dead-letter-routing-key", value = RabbitConfiguration.ERROR_ROUTING_KEY)
                }
            ),
    exchange = @Exchange(value = "core.exchange"),
    key = "core.route")
)
public void errorListener(final Message message) {

    try {

        .......

    } catch (IOException e) {

        // I would like to set value for x-first-death-reason or set
        // custom header if possible.
        throw new AmqpRejectAndDontRequeueException(e.getMessage());
    }
} 

1 个答案:

答案 0 :(得分:1)

没有; amqp协议不允许消费者修改被拒绝的消息。您必须自己发布到DLQ,而不是让RabbitMQ路由它。