当前位置:网站首页>延时队列优化 (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只会检查第一个消息是否过期,如果过期则丢到死信队列,
如果第一个消息的延时时长很长,而第二个消息的延时时长很短,第二个消息并不会优先得到执行。
边栏推荐
- 中集世联达工业级成熟航运港口人工智能AI产品规模化应用,打造新一代高效能智慧港口和创新数字港口,全球港航人工智能能领军者中集飞瞳
- Scrapy框架介绍
- scrapy基本使用
- Anaconda Navigator stuck on loading applications
- 荐号 | 对你有恩的人,不要请吃饭来报答
- 自然语言处理nltk
- LeetCode 练习——关于查找数组元素之和的两道题
- 你好好想想,你真的需要配置中心吗?
- 【HarmonyOS】【ARK UI】HarmonyOS ets语言怎么实现双击返回键退出
- 网络基础(二)-Web服务器-简介——WampServer集成服务器软件之Apache+MySQL软件安装流程 & netstat -an之检测计算机的端口是否占用
猜你喜欢

使用postman调接口报Content type ‘text/plain;charset=UTF-8‘ not supported

432.4 FPS 快STDC 2.84倍 | LPS-Net 结合内存、FLOPs、CUDA实现超快语义分割模型

OSPF详解(3)

图解LeetCode——11. 盛最多水的容器(难度:中等)

国轩高科瑞交所上市:募资近7亿美元 为瑞士今年最大融资项目

基于inquirer封装一个控制台文件选择器

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

kotlin by lazy

CCNA-ACL(访问控制列表)标准ACL 扩展ACL 命名ACL

【Pointing to Offer】Pointing to Offer 18. Delete the node of the linked list
随机推荐
基础架构之Redis
Vulkan与OpenGL对比——Vulkan的全新渲染架构
荐书 | 推荐好评如潮的3本数据库书籍
深化校企合作 搭建技术技能人才成长“立交桥”
OneFlow源码解析:Op、Kernel与解释器
while,do while,for循环语句
Codeblocks + Widgets create window code analysis
ESP8266-Arduino编程实例-HC-SR04超声波传感器驱动
NC | 西湖大学陶亮组-TMPRSS2“助攻”病毒感染并介导索氏梭菌出血毒素的宿主入侵...
固定资产可视化智能管理系统
攻防世界web-Cat
Fixed asset visualization intelligent management system
第14章 类型信息
你好,我的新名字叫“铜锁/Tongsuo”
【PHPWord】PHPOffice 套件之PHPWord快速入门
【Pointing to Offer】Pointing to Offer 18. Delete the node of the linked list
图解LeetCode——11. 盛最多水的容器(难度:中等)
cocos creater 热更重启导致崩溃
6块钱1斤,日本公司为何来中国收烟头?
原生js系列