当前位置:网站首页>Delay queue optimization (2)
Delay queue optimization (2)
2022-07-30 18:33:00 【a breezy】
A new queue QC is added here, the binding relationship is as follows, the queue does not set TTL time
Configuration class file:
@Bean("queueC")public Queue queueC(){HashMap args = new HashMap();args.put("x-dead-letter-exchange",Y_DEAD_LETTER_EXCHANGE);args.put("x-dead-letter-routing-key","YD");// No TTL property declared herereturn QueueBuilder.durable(QUEUE_C).withArguments(args).build();}@Beanpublic Binding queueBindingX(@Qualifier("queueC") Queue queueC,@Qualifier("xExchange") DirectExchange exchange){return BindingBuilder.bind(queueC).to(exchange).with("XC");}
Producer:
@[email protected]("ttl")@RestControllerpublic class Produce01 {@Autowiredprivate RabbitTemplate rabbitTemplate;// @GetMapping("sendMsg/{message}")// public void sendMsg(@PathVariable String message)// {//// log.info("Current time: {}, send a message to two TTL queues: {}", new Date(), message);// rabbitTemplate.convertAndSend("X","XA","message from 10s"+message);// rabbitTemplate.convertAndSend("X","XB","The message comes from 40s"+message);// }@GetMapping("sendExpirationMsg/{message}/{ttlTime}")public void senMsg(@PathVariable String message,@PathVariable String ttlTime){log.info("Current time: {}, send a TTL message with duration {} milliseconds to queue C:{}", new Date(), ttlTime, message);rabbitTemplate.convertAndSend("X","XC",message, correlationData ->{correlationData.getMessageProperties().setExpiration(ttlTime);return correlationData;});}}
Consumer:
@[email protected] class Consumer {@RabbitListener(queues = "QD")public void receiveD(Message message, Channel channel){String s = new String(message.getBody());log.info("Current time{}, message received by dead letter queue D---->{}",new Date(),s);}}
p>
It doesn't seem to be a problem, but at the beginning, it was introduced that if you use the method of setting TTL on the message property, the message may not "die" on time, because RabbitMQ will only check the firstWhether the message is expired, if it expires, it will be thrown into the dead letter queue,
If the first message has a long delay and the second message has a short delay, the second message will not be executed first.
边栏推荐
猜你喜欢
基础架构之Mongo
kotlin的by lazy
网络基础(二)-Web服务器-简介——WampServer集成服务器软件之Apache+MySQL软件安装流程 & netstat -an之检测计算机的端口是否占用
Recommendation | People who are kind to you, don't repay them by inviting them to eat
The use of @ symbol in MySql
Scrapy framework is introduced
【Pointing to Offer】Pointing to Offer 18. Delete the node of the linked list
【HMS core】【FAQ】Account Kit、MDM能力、push Kit典型问题合集6
延时队列优化 (2)
猎豹移动终于递交年报:年营收7.85亿 腾讯持股16.6%
随机推荐
Codeblocks + Widgets create window code analysis
网络基础(三)01-网络的基础概念——URL地址组成之协议、主机地址、路径和参数&127.0.0.1本地回环地址& 查看网址IP地址并访问之ping空格+网址&netstat -anb查看本机占用端口
Critical Reviews | A review of the global distribution of antibiotics and resistance genes in farmland soil by Nannong Zou Jianwen's group
Go 系统收集
What kind of framework is friendly to developers?
6块钱1斤,日本公司为何来中国收烟头?
OneFlow源码解析:Op、Kernel与解释器
【剑指 Offe】剑指 Offer 18. 删除链表的节点
【AGC】增长服务2-应用内消息示例
CMake库搜索函数居然不搜索LD_LIBRARY_PATH
软件测试13年从业经验的前辈,总结的5条测试就业建议....
延时队列优化 (2)
Redis for infrastructure
「Redis应用与深度实践笔记」,深得行业人的心,这还不来看看?
CCNA-ACL(访问控制列表)标准ACL 扩展ACL 命名ACL
Two-point answer naked question (plus a little pigeonhole principle)
C# wpf 无边框窗口添加阴影效果
【剑指 Offer】剑指 Offer 22. 链表中倒数第k个节点
AI Basics: Graphical Transformer
Scrapy框架介绍