当前位置:网站首页>Introduction to dead letter queue (two consumers, one producer)
Introduction to dead letter queue (two consumers, one producer)
2022-07-05 20:17:00 【Why not sell egg cakes well】
Sort out the dead letter queue .
Messages that cannot be consumed
Dead letter source
news TTL Be overdue
The queue has reached its maximum length
The queue is full , No more messages can be added to mq
The news was rejected
50 Dead letter code architecture diagram
Direct switch zhangsan By C1 consumption
Dead letter switch lisi Add to dead-queue By C2 consumption
51 c1 consumer
public class Consumer01{
// Common switch name
public static final String NORMAL_EXCHANGE="normal_exchange";
// Dead letter switch
public static final String DEAD_EXCHANGE="dead_exchange";
// Common queue name
public static final String NORMAL_QUEUE="normal_queue";
// Dead letter queue name
public static final String DEAD_QUEUE="dead_queue";
public static void main() throws Exception{
Channel channel=RabbitMqUtil.getChannel();
// Declare a common switch / Dead letter switch
channel.exchangeDeclare(NORMAL_EXCHANGE,BuiltinExchangeType.DIRECT);
channel.exchangeDeclare(DEAD_EXCHANGE,BuiltinExchangeType.DIRECT);
// Declare a normal queue
Map<String ,Object> arguments=new HashMap<>();
// Expiration time
//arguments.put("x-message-ttl",1000000);
// The dead letter switch after the normal queue setting expires
arguments.put("x-dead-letter-exchange",DEAD_EXCHANGE);
// Set dead letter RoutingKey
arguments.put("x-dead-letter-routing-key","lisi");
channel.queueDeclare(NORMAL_QUEUE,false,false,false,null);
// Dead letter queue
channel.queueDeclare(DEAD_QUEUE,false,false,false,null);
// Bind common switches and queues
channel.queueBind(NORMAL_QUEUE,NORMAL_EXCHANGE,"zhangsan");
// Bind dead letter switch and dead letter queue
channel.queueBind(DEAD_QUEUE,DEAD_EXCHANGE,"lisi");
sout(" Waiting to receive message ");
// Callback function
DeliverCallback deliverCallback=(consumerTag,message)->{
sout("Consumer01 When receiving messages "+new String(message.getBody(),"UTF-8"));
};
channel.basicConsume(NORMAL_QUEUE,true,deliverCallback,consumeTag->{
});
}
}
52 producer
public class Producer{
// Common switch name
public static final String NORMAL_EXCHANGE="normal_exchange";
public static void main() throws Exception{
Channel channel=RabbitMaUtils.getChannel();
// Dead letter news
AMQP.BasicProperties=new AMQP.BasicProperties().builder().expration("10000").build();
// Dead letter news Set up ttl Time
for(int i=1;i<11;i++){
String message="info"+i;
channel.basicPublish(NORMAL_EXCHANGE,"zhangsan",properties,message.getBytes());
}
}
}
Stop the consumer , The message is forwarded to the dead letter queue
53 consumer 2
This simple , It is simply to receive messages forwarded by ordinary queues for consumption .
public class Consumer02{
// Dead letter queue name
public static final String DEAD_QUEUE="dead_queue";
public static void main() throws Exception{
Channel channel=RabbitMqUtil.getChannel();
sout(" Waiting to receive message ");
DeliverCallback deliverCallback=(consumerTag,message)->{
sout("Consumer02 When receiving messages "+new String(message.getBody(),"UTF-8"));
};
channel.basicConsume(NORMAL_QUEUE,true,deliverCallback,consumeTag->{
});
}
}
边栏推荐
- - Oui. Net Distributed Transaction and Landing Solution
- 19 Mongoose模块化
- Minimum commission for stock trading account opening, where to open an account with low commission? Is it safe to open an account on your mobile phone
- leetcode刷题:二叉树16(路径总和)
- c语言oj得pe,ACM入门之OJ~
- 关于BRAM IP复位的优先级
- .Net分布式事务及落地解决方案
- [quick start of Digital IC Verification] 6. Quick start of questasim (taking the design and verification of full adder as an example)
- Interviewer: what is the internal implementation of set data types in redis?
- leetcode刷题:二叉树12(二叉树的所有路径)
猜你喜欢
解决php无法将string转换为json的办法
.Net分布式事務及落地解决方案
[quick start of Digital IC Verification] 6. Quick start of questasim (taking the design and verification of full adder as an example)
JS implementation prohibits web page zooming (ctrl+ mouse, +, - zooming effective pro test)
基础篇——配置文件解析
秋招字节面试官问你还有什么问题?其实你已经踩雷了
How to select the Block Editor? Impression notes verse, notation, flowus
Enter the parallel world
Debezium series: record the messages parsed by debezium and the solutions after the MariaDB database deletes multiple temporary tables
JVMRandom不可设置种子|问题追溯|源码追溯
随机推荐
mongodb基操的练习
解决Thinkphp框架应用目录下数据库配置信息修改后依然按默认方式连接
Enter the parallel world
USACO3.4 “破锣摇滚”乐队 Raucous Rockers - DP
[C language] merge sort
July 4, 2022 - July 10, 2022 (UE4 video tutorial MySQL)
c语言oj得pe,ACM入门之OJ~
微信小程序正则表达式提取链接
CTF reverse Foundation
Go language | 03 array, pointer, slice usage
.Net分布式事務及落地解决方案
Interviewer: what is the internal implementation of set data types in redis?
中金财富在网上开户安全吗?
How to retrieve the root password of MySQL if you forget it
【数字IC验证快速入门】2、通过一个SoC项目实例,了解SoC的架构,初探数字系统设计流程
2020 CCPC 威海 - A. Golden Spirit(思维),D. ABC Conjecture(大数分解 / 思维)
c語言oj得pe,ACM入門之OJ~
nprogress插件 进度条
Debezium series: modify the source code to support drop foreign key if exists FK
Leetcode skimming: binary tree 12 (all paths of binary tree)