【RabbitMQ】07-业务幂等处理
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. 方式二
基于业务
原文地址:https://blog.csdn.net/qq_45722630/article/details/143688415
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!