当前位置:网站首页>延时消息队列
延时消息队列
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);
}
}
如何保证消息可靠性
消息丢失

消息重复

消息积压

作者声明
如有问题,欢迎指正!
边栏推荐
- 智能合约安全——私有数据访问
- DocuWare 文件管理与工作流程自动化案例研究——DocuWare 工作流程功能使在家工作的员工能够保持沟通和高效工作,支持混合环境
- 关于String的一些思考
- Container sorting case
- 从实例来看DAO:权力分散的伟大尝试
- Mac 中 MySQL 的安装与卸载
- 使用bat脚本以json格式导出mongo数据库中指定表数据
- How to use Databricks for data analysis on TiDB Cloud | TiDB Cloud User Guide
- Huawei issues another summoning order for "Genius Boys"!He, who had given up an annual salary of 3.6 million, also made his debut
- [机缘参悟-53]:《素书》-3-修身养志[求人之志章第三]
猜你喜欢

5. DOM

Mac 中 MySQL 的安装与卸载

English语法_不定代词 - both / either / neither

学习 MySQL 需要知道的 28 个小技巧

DDS Arbitrary Waveform Output Based on FPGA

吃透Chisel语言.29.Chisel进阶之通信状态机(一)——通信状态机:以闪光灯为例

Start learning C language

惊艳!京东T8纯手码的Redis核心原理手册,基础与源码齐下

Understand the Chisel language. 29. Chisel advanced communication state machine (1) - communication state machine: take the flash as an example

基于5G的仓储信息化解决方案2022
随机推荐
Container sorting case
华为无线设备Mesh配置命令
Why did I switch from developer to testing, 3 years software testing engineer, tell you the secret of this
MongoDB启动报错 Process: 29784 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
4 senior experts share the insider architecture design and implementation principles of Flink technology with years of experience in large factories
华为再发「天才少年」召集令!曾放弃360万年薪的他也来首秀
v-model组件化编程应用
Machine learning difference in the competition and industry application
调试 - 笔记
Desktop Software Development Framework Awards
元宇宙邮局AI航天主题系列数字藏品 将于7月30日10:00点上线“元邮数藏”
MySQL客户端工具的使用与MySQL SQL语句
新时代背景下智慧城市的建设与5G技术有何关联
阿里CTO程立:阿里巴巴的开源历程、理念和实践
【回归预测-lssvm分类】基于最小二乘支持向量机lssvm实现数据分类代码
The website adds a live 2d kanban girl that can dress up and interact
Installing and Uninstalling MySQL on Mac
JUC常见的线程池源码学习 02 ( ThreadPoolExecutor 线程池 )
自动化办公|办公软件和亿图脑图MindMaster快捷键
JUC common thread pool source learning 02 ( ThreadPoolExecutor thread pool )