当前位置:网站首页>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->{
});
}
}
边栏推荐
- leetcode刷题:二叉树14(左叶子之和)
- 【数字IC验证快速入门】6、Questasim 快速上手使用(以全加器设计与验证为例)
- JVMRandom不可设置种子|问题追溯|源码追溯
- .Net分布式事务及落地解决方案
- model方法
- Is the education of caiqiantang reliable and safe?
- 14. Users, groups, and permissions (14)
- kubernetes资源对象介绍及常用命令(五)-(ConfigMap&Secret)
- Hong Kong stocks will welcome the "best ten yuan store". Can famous creative products break through through the IPO?
- ICTCLAS用的字Lucene4.9捆绑
猜你喜欢
JS implementation prohibits web page zooming (ctrl+ mouse, +, - zooming effective pro test)
无卷积骨干网络:金字塔Transformer,提升目标检测/分割等任务精度(附源代码)...
Leetcode skimming: binary tree 17 (construct binary tree from middle order and post order traversal sequence)
Leetcode brush questions: binary tree 11 (balanced binary tree)
【愚公系列】2022年7月 Go教学课程 004-Go代码注释
基础篇——配置文件解析
After 95, Alibaba P7 published the payroll: it's really fragrant to make up this
IC科普文:ECO的那些事儿
Unity editor extended UI control
Autumn byte interviewer asked you any questions? In fact, you have stepped on thunder
随机推荐
ICTCLAS用的字Lucene4.9捆绑
Elk distributed log analysis system deployment (Huawei cloud)
CTF逆向基础
Schema和Model
实操演示:产研团队如何高效构建需求工作流?
Scala basics [HelloWorld code parsing, variables and identifiers]
About the priority of Bram IP reset
无卷积骨干网络:金字塔Transformer,提升目标检测/分割等任务精度(附源代码)...
Go language | 01 wsl+vscode environment construction pit avoidance Guide
leetcode刷题:二叉树16(路径总和)
【c语言】快速排序的三种实现以及优化细节
零道云新UI设计中
怎么挑选好的外盘平台,安全正规的?
model方法
sun.misc.BASE64Encoder报错解决方法[通俗易懂]
selenium 元素信息
【数字IC验证快速入门】7、验证岗位中必备的数字电路基础知识(含常见面试题)
Go language | 03 array, pointer, slice usage
leetcode刷题:二叉树14(左叶子之和)
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