当前位置:网站首页>延时消息队列
延时消息队列
2022-07-30 14:40:00 【努力学习,努力爱你!】
使用场景


目的是保证事务最终一致性
消息的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中没有的情况下) * RabbitMQ中只要有就不会覆盖 */
@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);
}
}
如何保证消息可靠性
消息丢失

消息重复

消息积压

作者声明
如有问题,欢迎指正!
边栏推荐
- Meta首份元宇宙白皮书9大看点,瞄准80万亿美元市场
- In-depth analysis of Kubernetes application management
- Distributed pre-course: MySQL implements distributed locks
- Before quitting, make yourself a roll king
- MASM32v11编程调用Process32First失败: 程序发出命令,但命令长度不正确
- 学习 MySQL 需要知道的 28 个小技巧
- 第十一章 api mgmnt API 参考
- 关于容器的小案例
- Allure进阶-动态生成报告内容
- Fink异步IO的实战(关联维表)
猜你喜欢

Desktop Software Development Framework Awards

Web3创始人和建设者必备指南:如何构建适合的社区?

Flink实时仓库-DWS层(关键词搜索分析-自定义函数,窗口操作,FlinkSql设置水位线,保存数据到Clickhouse)模板代码

canal抓取数据

华为再发「天才少年」召集令!曾放弃360万年薪的他也来首秀

嵌入式开发:嵌入式基础知识——正确启动固件项目的 10 条建议

MPSK抗噪声性能对比(即MPSK标准误码率曲线)

This editor actually claims to be as fast as lightning!

Remember an experience of interviewing an outsourcing company, should you go?

基于FPGA的DDS任意波形输出
随机推荐
【元胞自动机】基于元胞自动机模拟生命演化、病毒感染等实例附matlab代码
SSE for Web Message Push
一文读懂网络效应对Web3的重要意义
5. DOM
Normal and escaped strings for postgresql
开始学习C语言了
localhost与127.0.0.1
自动化办公|办公软件和亿图脑图MindMaster快捷键
惊艳!京东T8纯手码的Redis核心原理手册,基础与源码齐下
localhost with 127.0.0.1
国内数字藏品的乱象与未来
English语法_不定代词 - both / either / neither
4位资深专家多年大厂经验分享出Flink技术内幕架构设计与实现原理
Alluxio为Presto赋能跨云的自助服务能力
Go to Tencent for an interview and let people turn left directly: I don't know idempotency!
视频切换播放的例子(视频切换范例)代码
952. 按公因数计算最大组件大小 : 枚举质因数 + 并查集运用题
超T动力 盈运天下——中国重汽黄河/豪沃WP14T产品首发荣耀上市!
[深入研究4G/5G/6G专题-46]: 5G Link Adaption链路自适应-2-常见缩略语
DDS Arbitrary Waveform Output Based on FPGA