无法在兔子侦听器 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}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...