当前位置:网站首页>12. Priority queue and inert queue
12. Priority queue and inert queue
2022-07-29 04:15:00 【Machoul】
Priority queue
How to add priority
- choice
Maximum priority
, Value specifying priority , Set the range to 0-255, If the value is 10, So that is 0-10, Maximum not exceeding 255
Code form
Map<String,Object> params = new HashMap<>();
params.put("x-max-priority",10);
channel.queueDeclare("hello",true,false,false,params);
Case presentation
Producer code
/** * Priority queue producer */
public class PriorityProducer {
public static void main(String[] args) throws IOException {
Channel channel = RabbitUtil.getChannel();
AMQP.BasicProperties properties = new AMQP.BasicProperties().builder().priority(5).build();
for (int i = 0; i < 10; i++) {
String message = "info"+ i;
if (i==5){
channel.basicPublish("","hello",properties,message.getBytes(StandardCharsets.UTF_8));
}else {
channel.basicPublish("","hello",null,message.getBytes(StandardCharsets.UTF_8));
}
}
System.out.println(" Send message complete ");
}
}
Consumer code
/** * Priority queue consumer */
public class PriorityConsumer {
public static void main(String[] args) throws IOException {
Channel channel = RabbitUtil.getChannel();
Map<String,Object> params = new HashMap<>();
params.put("x-max-priority",10);
channel.queueDeclare("hello",true,false,false,params);
System.out.println(" Consumers start waiting for consumption ...");
DeliverCallback deliverCallback = (consumerTag, message) -> {
String received = new String( message.getBody());
System.out.println(" Message received :"+received);
};
channel.basicConsume("hello",true,deliverCallback,consumerTag -> {
System.out.println(" Called when the consumer cannot consume the message , If the queue is deleted ");
});
}
}
result
- Start the producer first , Then start the consumer , Find out
info5
Be consumed first - If you start the consumer first , Restart producer , Because the processing speed is fast enough , There is no message stack in the queue , So execute in order
Lazy queue
Lazy queues store messages to disk as much as possible , When consumers consume the corresponding message, it will be loaded into memory , An important design goal is to support longer queues , That is, support more message storage
When messages cannot be consumed for a long time due to various reasons, resulting in accumulation , Inert queues are necessary
There are two modes of queues :default and lazy. have access to x-queue-mode
To set the mode of the queue , The value is default
and lazy
.
Declaration of inert queue
Map<String,Object> params = new HashMap();
params.put("x-queue-mode","lazy");
channel.queueDeclare("hello",false,false,false,params);
边栏推荐
- The solution of porting stm32f103zet6 program to c8t6+c8t6 download program flash timeout
- Locally call tensorboard and Jupiter notebook on the server (using mobaxterm)
- [common commands]
- Safari's compatibility with Z-index
- 不会就坚持67天吧 平方根
- Taobao product details interface (product details page data interface)
- MPU6050
- [Openstack] keystone,nova
- 基于STM32和阿里云的环境检测系统设计
- Install the laser of ROS_ scan_ Problems encountered in match library (I)
猜你喜欢
Applet: Area scrolling, pull-down refresh, pull-up load more
不会就坚持69天吧 合并区间
不会就坚持59天吧 替换单词
Value transmission and address transmission of C language, pointer of pointer
MySQL gets the maximum value record by field grouping
[Openstack] keystone,nova
[kvm] create virtual machine from kickstart file
10.回退消息
从淘宝,天猫,1688,微店,京东,苏宁,淘特等其他平台一键复制商品到拼多多平台(批量上传宝贝详情接口教程)
12.优先级队列和惰性队列
随机推荐
不会就坚持60天吧 神奇的字典
Locally call tensorboard and Jupiter notebook on the server (using mobaxterm)
MPU6050
顺序表和链表
Lua language (stm32+2g/4g module) and C language (stm32+esp8266) methods of extracting relevant data from strings - collation
有一种密码学专用语言叫做ASN.1
安装postgis时报找不到“POSTGIS_VERSION”这个函数
Blood cases caused by < meta charset=UTF-8> -- Analysis of common character codes
Copy products with one click from Taobao, tmall, 1688, wechat, jd.com, Suning, taote and other platforms to pinduoduo platform (batch upload baby details Interface tutorial)
不会就坚持70天吧 数组中第k大的数
不会就坚持71天吧 链表排序
[material delivery UAV] record (ROS + Px4 + yolov5 + esp8266 + steering gear)
不会就坚持67天吧 平方根
Database SQL statement realizes function query of data decomposition
Shielding ODBC load balancing mode in gbase 8A special scenarios?
HC06 HC05 BT
C语言:结构体简单语法总结
"Weilai Cup" 2022 Niuke summer multi school training camp 2H
C语言力扣第61题之旋转链表。双端队列与构造循环链表
不会就坚持69天吧 合并区间