当前位置:网站首页>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->{
});
}
}
边栏推荐
- About the priority of Bram IP reset
- 本季度干货导航 | 2022年Q2
- leetcode刷题:二叉树16(路径总和)
- 1: Citation;
- ICTCLAS word Lucene 4.9 binding
- 关于BRAM IP复位的优先级
- After 95, Alibaba P7 published the payroll: it's really fragrant to make up this
- .Net分布式事務及落地解决方案
- 无卷积骨干网络:金字塔Transformer,提升目标检测/分割等任务精度(附源代码)...
- [quick start of Digital IC Verification] 6. Quick start of questasim (taking the design and verification of full adder as an example)
猜你喜欢

零道云新UI设计中

Leetcode brush question: binary tree 13 (the same tree)

计算lnx的一种方式
![[quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives](/img/90/88a1f79a07016738d2688548e21949.png)
[quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives

How to select the Block Editor? Impression notes verse, notation, flowus

Debezium series: record the messages parsed by debezium and the solutions after the MariaDB database deletes multiple temporary tables

leetcode刷题:二叉树13(相同的树)

IC科普文:ECO的那些事儿

Autumn byte interviewer asked you any questions? In fact, you have stepped on thunder

Let's talk about threadlocalinsecurerandom
随机推荐
处理文件和目录名
kubernetes资源对象介绍及常用命令(五)-(ConfigMap&Secret)
Is it safe for Galaxy Securities to open an account online?
Elk distributed log analysis system deployment (Huawei cloud)
【数字IC验证快速入门】6、Questasim 快速上手使用(以全加器设计与验证为例)
Reinforcement learning - learning notes 4 | actor critical
【愚公系列】2022年7月 Go教学课程 004-Go代码注释
Jvmrandom cannot set seeds | problem tracing | source code tracing
selenium 元素信息
关于BRAM IP复位的优先级
【数字IC验证快速入门】3、数字IC设计全流程介绍
Go language | 03 array, pointer, slice usage
leetcode刷题:二叉树12(二叉树的所有路径)
实操演示:产研团队如何高效构建需求工作流?
Station B up builds the world's first pure red stone neural network, pornographic detection based on deep learning action recognition, Chen Tianqi's course progress of machine science compilation MLC,
leetcode刷题:二叉树16(路径总和)
死信队列入门(两个消费者,一个生产者)
字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验
Schema和Model
【数字IC验证快速入门】9、Verilog RTL设计必会的有限状态机(FSM)