当前位置:网站首页>延时队列优化 (2)
延时队列优化 (2)
2022-07-30 18:28:00 【一个风轻云淡】
在这里新增了一个队列QC,绑定关系如下,该队列不设置TTL时间

配置类文件:
@Bean("queueC")
public Queue queueC()
{
HashMap<String, Object> args = new HashMap<String, Object>();
args.put("x-dead-letter-exchange",Y_DEAD_LETTER_EXCHANGE);
args.put("x-dead-letter-routing-key","YD");
//在这里没有声明TTL属性
return QueueBuilder.durable(QUEUE_C).withArguments(args).build();
}
@Bean
public Binding queueBindingX(@Qualifier("queueC") Queue queueC,@Qualifier("xExchange") DirectExchange exchange)
{
return BindingBuilder.bind(queueC).to(exchange).with("XC");
}生产者:
@Slf4j
@RequestMapping("ttl")
@RestController
public class Produce01 {
@Autowired
private RabbitTemplate rabbitTemplate;
// @GetMapping("sendMsg/{message}")
// public void sendMsg(@PathVariable String message)
// {
//
// log.info("当前时间:{},发送一条消息给俩个TTL队列:{}", new Date(),message);
// rabbitTemplate.convertAndSend("X","XA","消息来于10s"+message);
// rabbitTemplate.convertAndSend("X","XB","消息来于40s"+message);
// }
@GetMapping("sendExpirationMsg/{message}/{ttlTime}")
public void senMsg(@PathVariable String message,@PathVariable String ttlTime)
{
log.info("当前时间:{},发送一条时长{}毫秒TTL信息给队列C:{}", new Date(),ttlTime, message);
rabbitTemplate.convertAndSend("X","XC",message, correlationData ->{
correlationData.getMessageProperties().setExpiration(ttlTime);
return correlationData;
});
}
}
消费者:
@Slf4j
@Component
public class Consumer {
@RabbitListener(queues = "QD")
public void receiveD(Message message, Channel channel)
{
String s = new String(message.getBody());
log.info("当前时间{},死信队列D接收到消息---->{}",new Date(),s);
}
}
![]()
看起来似乎没什么问题,但是在最开始的时候,就介绍过如果使用在消息属性上设置TTL的方式,消息可能并不会按时“死亡“,因为RabbitMQ只会检查第一个消息是否过期,如果过期则丢到死信队列,
如果第一个消息的延时时长很长,而第二个消息的延时时长很短,第二个消息并不会优先得到执行。
边栏推荐
- 【Pointing to Offer】Pointing to Offer 22. The kth node from the bottom in the linked list
- Presto 中 lookUp Join的实现
- 单例模式 (Singleton)
- SwiftUI iOS Boutique Open Source Project Complete Baked Food Recipe App based on SQLite (tutorial including source code)
- AI Basics: Graphical Transformer
- Linux-安装MySQL(详细教程)
- 沃尔沃中国的年中总结,在“安全感”中寻找未来
- 5分钟搞懂MySQL - 行转列
- Pytorch foundation -- tensorboard use (1)
- linux 安装mysql8.0 超详细教程(实战多次)
猜你喜欢

Confluence OGNL注入漏洞复现(CVE-2022-26134)

Kettle--MySQL生产数据库千万、亿级数据量迁移方案及性能优化

固定资产可视化智能管理系统

Redis for infrastructure

6 yuan per catty, why do Japanese companies come to China to collect cigarette butts?

ESP8266-Arduino programming example-HC-SR04 ultrasonic sensor driver

【剑指 Offe】剑指 Offer 18. 删除链表的节点

这玩意儿都能优化?果然是细节都在魔鬼里。

【AGC】增长服务2-应用内消息示例

NC | Tao Liang Group of West Lake University - TMPRSS2 "assists" virus infection and mediates the host invasion of Clostridium sothrix hemorrhagic toxin...
随机推荐
Redis for infrastructure
Anaconda Navigator stuck on loading applications
网络基础(二)-Web服务器-简介——WampServer集成服务器软件之Apache+MySQL软件安装流程 & netstat -an之检测计算机的端口是否占用
node封装一个控制台进度条插件
沉浸式体验科大讯飞2022消博会“官方指定产品”
时序数据库在船舶风险管理领域的应用
使用postman调接口报Content type ‘text/plain;charset=UTF-8‘ not supported
单例模式 (Singleton)
LeetCode 练习——关于查找数组元素之和的两道题
【HMS Core】【FAQ】运动健康、音频编辑、华为帐号服务 典型问题合集7
CMake library search function does not search LD_LIBRARY_PATH
OSPF详解(4)
5分钟搞懂MySQL - 行转列
AWS console
深化校企合作 搭建技术技能人才成长“立交桥”
CMake库搜索函数居然不搜索LD_LIBRARY_PATH
Scrapy框架介绍
Leetcode数据库系列题解合集(持续更新)
Chapter 14 Type Information
Immersive experience iFLYTEK 2022 Consumer Expo "Official Designated Product"