1. 方式一
序列化设置唯一Id。
@Bean
public MessageConverter messageConverter() {
Jackson2JsonMessageConverter jjmc = new Jackson2JsonMessageConverter();
jjmc.setCreateMessageIds(true);
return jjmc;
}
@RabbitListener(bindings = @QueueBinding(
value = @Queue(name = "direct.queue1"),
exchange = @Exchange(name = "hmall.direct", type = ExchangeTypes.DIRECT),
key = {"red", "yellow"}
))
public void topicLister1(Message msg) {
log.info("测试" + msg.getMessageProperties().getMessageId());
System.out.println(new String(msg.getBody()));
// throw new RuntimeException("用于测试的异常");
}
2. 方式二
基于业务