当前位置:网站首页>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->{
});
}
}
边栏推荐
- Summer Challenge harmonyos - realize message notification function
- .Net分布式事务及落地解决方案
- document方法
- 1: Citation;
- Autumn byte interviewer asked you any questions? In fact, you have stepped on thunder
- Database logic processing function
- Unity编辑器扩展 UI控件篇
- Oracle-表空间管理
- Practical demonstration: how can the production research team efficiently build the requirements workflow?
- C langue OJ obtenir PE, ACM démarrer OJ
猜你喜欢
死信队列入门(两个消费者,一个生产者)
走入并行的世界
【数字IC验证快速入门】8、数字IC中的典型电路及其对应的Verilog描述方法
Jvmrandom cannot set seeds | problem tracing | source code tracing
Solve the problem that the database configuration information under the ThinkPHP framework application directory is still connected by default after modification
Go language | 01 wsl+vscode environment construction pit avoidance Guide
基础篇——配置文件解析
.Net分布式事务及落地解决方案
Oracle tablespace management
Scala basics [HelloWorld code parsing, variables and identifiers]
随机推荐
2020 CCPC 威海 - A. Golden Spirit(思维),D. ABC Conjecture(大数分解 / 思维)
计算lnx的一种方式
【数字IC验证快速入门】9、Verilog RTL设计必会的有限状态机(FSM)
selenium 元素信息
Summer Challenge harmonyos - realize message notification function
微信小程序正则表达式提取链接
[quick start of Digital IC Verification] 9. Finite state machine (FSM) necessary for Verilog RTL design
ffplay文档[通俗易懂]
Go language | 03 array, pointer, slice usage
c語言oj得pe,ACM入門之OJ~
js方法传Long类型id值时会出现精确损失
信息学奥赛一本通 1339:【例3-4】求后序遍历 | 洛谷 P1827 [USACO3.4] 美国血统 American Heritage
leetcode刷题:二叉树10(完全二叉树的节点个数)
leetcode刷题:二叉树13(相同的树)
Leetcode skimming: binary tree 17 (construct binary tree from middle order and post order traversal sequence)
.Net分布式事务及落地解决方案
处理文件和目录名
Interviewer: what is the internal implementation of set data types in redis?
Parler de threadlocal insecurerandom
Leetcode brush questions: binary tree 11 (balanced binary tree)