无法在rabbit侦听器springboot中检索x-death标头



我使用的是rabbit mq,我想访问消息重试,但我总是得到一个null读取x-death值,如本例所示。但是,消息的阅读是正确的。

@Component
@RabbitListener(queues = "myQueue")
public class AdyenNotificationMessageListener {
@RabbitHandler
public void processMessage(byte[] messageByte, @Header(name = "x-death", required = false) Map<?, ?> death) {
// death is always null
}
}

springboot version : '2.4.1'spring-boot-starter-amqp'配合使用

任何关于我可能做错了什么的暗示都将不胜感激。

它对我来说很好;你确定邮件有标题吗?

@SpringBootApplication
public class So68231711Application {
public static void main(String[] args) {
SpringApplication.run(So68231711Application.class, args);
}
@Bean
Queue queue() {
return QueueBuilder.durable("so68231711")
.deadLetterExchange("")
.deadLetterRoutingKey("so68231711.dlq")
.build();
}
@Bean
Queue dlq() {
return new Queue("so68231711.dlq");
}
@RabbitListener(queues = "so68231711")
public void listen(String in) {
System.out.println(in);
throw new AmqpRejectAndDontRequeueException("toDLQ");
}
@RabbitListener(queues = "so68231711.dlq")
public void listenDlq(String in, @Header(name = "x-death", required=false) Map<?, ?> death) {
System.out.println(in);
System.out.println(death);
}
}
foo
... Execution of Rabbit message listener failed.
...
foo
{reason=rejected, count=1, exchange=, time=Tue Jul 06 11:09:30 EDT 2021, routing-keys=[so68231711], queue=so68231711}

最新更新