当前位置:网站首页>Delayed message queue
Delayed message queue
2022-07-30 15:32:00 【Study hard and love you hard!】
使用场景


The purpose is to ensure eventual consistency of transactions
消息的TTL

Exchanges 死信

流程

整合使用
配置
package com.jhj.gulimall.ssoclient.config;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;
@Configuration
public class MyMQConfig {
/** * 容器中的Binding Queue Exchange 都会自动创建(RabbitMQ中没有的情况下) * RabbitMQAs long as there is, it will not be covered */
@Bean
public Queue orderDelayQueue(){
Map<String,Object> arguments = new HashMap<>();
//死信路由
arguments.put("x-dead-letter-exchange","order-event-exchange");
//死信路由键
arguments.put("x-dead-letter-routing-key","order.release.order");
//过期时间
arguments.put("x-message-ttl","60000");
Queue queue = new Queue("order.delay.queue", true, false, false,arguments);
return queue;
}
@Bean
public Queue orderReleaseQueue(){
Queue queue = new Queue("order.release.order.queue", true, false, false);
return queue;
}
@Bean
public Exchange orderEventExchange(){
return new TopicExchange("order-event-exchange", true, false);
}
@Bean
public Binding orderCreateOrderBinding(){
return new Binding("order.delay.queue", Binding.DestinationType.QUEUE,"order-event-exchange","order.create.order",null);
}
@Bean
public Binding orderReleaseOrderBinding(){
return new Binding("order.release.order.queue", Binding.DestinationType.QUEUE,"order-event-exchange","order.release.order",null);
}
}
发送
/** * 发送消息 */
@Test
public void sendMessage(){
rabbitTemplate.convertAndSend("order-event-exchange","order.create.order","test");
}
接收
@RabbitListener(queues = {
"order.release.order.queue"})
public void listener(Message message, String s, Channel channel){
message.getBody();
System.out.println(s);
try {
// 第二个参数代表 是否批量回复 确认成功回复 收货
channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
// 第二个参数代表 是否批量回复
// 第三个参数代表 是否重新放到queue中 退货 确认失败回复 false 丢弃 true 重新入队
//channel.basicNack(message.getMessageProperties().getDeliveryTag(),false,false);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
如何保证消息可靠性
消息丢失

消息重复

消息积压

作者声明
如有问题,欢迎指正!
边栏推荐
- 学习 MySQL 需要知道的 28 个小技巧
- Meta首份元宇宙白皮书9大看点,瞄准80万亿美元市场
- MongoDB starts an error Process: 29784 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
- 这个编辑器居然号称快如闪电!
- This editor actually claims to be as fast as lightning!
- postgresql的普通字符串和转义字符串
- Ts是什么?
- Redis cache penetration, breakdown, avalanche and consistency issues
- 分布式前修课:MySQL实现分布式锁
- 怎么判断两个字符串是否相等?
猜你喜欢
随机推荐
The highest level of wiring in the computer room, the beauty is suffocating
Normal and escaped strings for postgresql
Installing and Uninstalling MySQL on Mac
DDS Arbitrary Waveform Output Based on FPGA
About the data synchronization delay of MySQL master-slave replication
Flink optimization
闭包和装饰器
SLF4J的使用
MASM32v11编程调用Process32First失败: 程序发出命令,但命令长度不正确
Redis cache penetration, breakdown, avalanche and consistency issues
Meta首份元宇宙白皮书9大看点,瞄准80万亿美元市场
Huawei issues another summoning order for "Genius Boys"!He, who had given up an annual salary of 3.6 million, also made his debut
1222. 可以攻击国王的皇后-力扣双百代码
面试何惧调优!腾讯技术官私藏的性能优化方案手册,原理实战齐全
一文读懂网络效应对Web3的重要意义
ECCV 2022 | Towards Data Efficient Transformer Object Detectors
软件包 - 笔记
从实例来看DAO:权力分散的伟大尝试
微服务架构下的核心话题 (二):微服务架构的设计原则和核心话题
canal scrape data







