当前位置:网站首页>Code practice when the queue reaches the maximum length
Code practice when the queue reaches the maximum length
2022-07-27 03:21:00 【A light wind and light clouds】
producer 001
/**
* When the queue reaches the maximum length
*/
public class Producer001 {
private static final String NORMAL_EXCHANGE="normal_exchange";
public static void main(String[] args) throws Exception{
Channel channel = untils.getChannel();
channel.exchangeDeclare(NORMAL_EXCHANGE, BuiltinExchangeType.DIRECT);
// This message is used as the number limit of queues
for(int i=0;i<10;i++)
{
String message="info"+i;
channel.basicPublish(NORMAL_EXCHANGE,"zhangsan",null,message.getBytes(StandardCharsets.UTF_8));
System.out.println(" Producer sends message "+message);
}
}
}consumer 001
/**
* Average consumer with maximum queue length
*/
public class Consumer001 {
// General switch
private static final String NORMAL_EXCHANGE="normal_exchange";
// Dead letter switch
private static final String DEAD_EXCHANGE="dead_exchange";
public static void main(String[] args) throws Exception{
Channel channel = untils.getChannel();
// Declare dead letter switch , The type is direct
channel.exchangeDeclare(NORMAL_EXCHANGE, BuiltinExchangeType.DIRECT);
channel.exchangeDeclare(DEAD_EXCHANGE,BuiltinExchangeType.DIRECT);
// Declare dead letter queue
String deadQueue="dead_queue";
channel.queueDeclare(deadQueue,false,false,false,null);
// Dead letter queue binding exchange and routingKey value
channel.queueBind(deadQueue,DEAD_EXCHANGE,"lisi");
// The normal queue is bound to the dead letter queue
Map<String,Object> params=new HashMap<>();
// Set the dead letter switch in the normal queue , Parameters key It's a fixed value
params.put("x-dead-letter-exchange",DEAD_EXCHANGE);
// Set dead letter in normal queue routing-key, Parameters key It's a fixed value
params.put("x-dead-letter-routing-key", "lisi");
// Maximum limit length of normal queue settings
params.put("x-max-length",6);
System.out.println(" Waiting to receive message ....");
String normalQueue="normal_queue";
channel.queueDeclare(normalQueue,false,false,false,params);
channel.queueBind(normalQueue,NORMAL_EXCHANGE,"zhangsan");
DeliverCallback deliverCallback=(consumerTag, message) -> {
String s = new String(message.getBody(), StandardCharsets.UTF_8);
System.out.println("01 Message received "+s);
};
channel.basicConsume(normalQueue,true,deliverCallback,consumerTag -> {});
}
}result :

边栏推荐
- [learning notes, dog learning C] string + memory function
- Hcip day 14 notes
- Complete source code of mall applet project (wechat applet)
- 175. 组合两个表(非常简单)
- Compile and use protobuf Library in vs2019
- 优炫数据库集群如何唯一标识一条用户SQL
- Single case mode (double check lock)
- pip3 设置阿里云
- It's too strong. An annotation handles the data desensitization returned by the interface
- Zhang Ping, Alibaba cloud Solution Architect: system construction of cloud native digital safety production
猜你喜欢

How to use devaxpress WPF to create the first MVVM application in winui?

be based on. NETCORE development blog project starblog - (16) some new functions (monitoring / statistics / configuration / initialization)

Worthington果胶酶的特性及测定方案

Plato Farm全新玩法,套利ePLATO稳获超高收益

185. 部门工资前三高的所有员工(必会)

Annotation summary of differences between @autowired and @resource

抖音服务器带宽有多大,才能供上亿人同时刷?

How many implementation postures of delay queue? Daily essential skills!

Plato farm has a new way of playing, and the arbitrage eplato has secured super high returns

图解 SQL,这也太形象了吧!
随机推荐
二叉树(DAY 82)
周全的照护 解析LYRIQ锐歌电池安全设计
力扣(LeetCode)207. 课程表(2022.07.26)
Abbkine AbFluor 488 细胞凋亡检测试剂盒特点及实验建议
spark学习笔记(五)——sparkcore核心编程-RDD转换算子
[flask] the server obtains the file requested by the client
A test class understands beanutils.copyproperties
深入理解Mysql索引底层数据结构与算法
国内服务器与海外服务器用1个数据库,怎样可以访问的快?
Complete source code of mall applet project (wechat applet)
子模块cache缓存失效
Data Lake (20): Flink is compatible with iceberg, which is currently insufficient, and iceberg is compared with Hudi
Details of impala implementation plan
图解用户登录验证流程,写得太好了!
How big is the bandwidth of the Tiktok server for hundreds of millions of people to brush at the same time?
How to visit the latest version of burpsuite pro in vain
196. 删除重复的电子邮箱
“date: write error: No space left on device”解决
Activiti5.22.0扩展支持达国产数据库,以GBase据库为例
opiodr aborting process unknown ospid (21745) as a result of ORA-609