当前位置:网站首页>延时队列优化 (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只会检查第一个消息是否过期,如果过期则丢到死信队列,
如果第一个消息的延时时长很长,而第二个消息的延时时长很短,第二个消息并不会优先得到执行。
边栏推荐
- SQL行列转换
- mysql的多实例
- [Summary] 1396- 60+ VSCode plugins to create a useful editor
- Quickly build an e-commerce platform based on Amazon cloud technology serverless service - performance
- SQL存储过程详解
- 原生js系列
- Critical Reviews | A review of the global distribution of antibiotics and resistance genes in farmland soil by Nannong Zou Jianwen's group
- 积性函数
- 荐号 | 对你有恩的人,不要请吃饭来报答
- 【剑指 Offe】剑指 Offer 17. 打印从1到最大的n位数
猜你喜欢
6块钱1斤,日本公司为何来中国收烟头?
Critical Reviews | A review of the global distribution of antibiotics and resistance genes in farmland soil by Nannong Zou Jianwen's group
Quickly build an e-commerce platform based on Amazon cloud technology serverless service - performance
Linux-安装MySQL(详细教程)
网络基础(二)-Web服务器-简介——WampServer集成服务器软件之Apache+MySQL软件安装流程 & netstat -an之检测计算机的端口是否占用
基础架构之Redis
Recommended Books | Recommend 3 database books with rave reviews
OSPF详解(4)
NC | Tao Liang Group of West Lake University - TMPRSS2 "assists" virus infection and mediates the host invasion of Clostridium sothrix hemorrhagic toxin...
Meta元宇宙部门第二季度亏损28亿!仍要继续押注?元宇宙发展尚未看到出路!
随机推荐
毕业1年从事软件测试拿下11.5k,没有给98后丢脸吧...
What kind of framework is friendly to developers?
Pytorch基础--tensorboard使用(一)
猎豹移动终于递交年报:年营收7.85亿 腾讯持股16.6%
WeChat Mini Program Cloud Development | Urban Information Management
ESP8266-Arduino programming example-BMP180 air pressure temperature sensor driver
MYSQL(基本篇)——一篇文章带你走进MYSQL的奇妙世界
好未来单季营收2.24亿美元:同比降84% 张邦鑫持股26.3%
Quickly build an e-commerce platform based on Amazon cloud technology serverless service - performance
NC | 西湖大学陶亮组-TMPRSS2“助攻”病毒感染并介导索氏梭菌出血毒素的宿主入侵...
微信小程序云开发 | 城市信息管理
Critical Reviews | 南农邹建文组综述全球农田土壤抗生素与耐药基因分布
The large-scale application of artificial intelligence AI products in industrial-grade mature shipping ports of CIMC World Lianda will create a new generation of high-efficiency smart ports and innova
攻防世界web-Cat
NC | Tao Liang Group of West Lake University - TMPRSS2 "assists" virus infection and mediates the host invasion of Clostridium sothrix hemorrhagic toxin...
A senior with 13 years of experience in software testing, summed up 5 test employment suggestions....
【剑指 Offe】剑指 Offer 17. 打印从1到最大的n位数
基础架构之Mongo
ByteArrayInputStream 类源码分析
【HarmonyOS】【FAQ】鸿蒙问题合集3