问题描述
我正在使用 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}