当前位置:网站首页>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
info5Be 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);
边栏推荐
- 11.备份交换机
- 安装postgis时报找不到“POSTGIS_VERSION”这个函数
- Differences and principles of bio, NiO and AIO
- Taobao product details interface (product details page data interface)
- 通过js来实现一元二次方程的效果,输入a,b,c系数后可计算出x1和x2的值
- RMAN do not mark expired backups
- 小程序:区域滚动、下拉刷新、上拉加载更多
- 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)
- AssertionError(“Torch not compiled with CUDA enabled“)
- STM32F103ZET6程序移植为C8T6+C8T6下载程序flash timeout的解决方案
猜你喜欢

Whole house WiFi solution: mesh router networking and ac+ap

Class starts! See how smardaten decomposes complex business scenarios

Svg -- loading animation

不会就坚持69天吧 合并区间

Design of environment detection system based on STM32 and Alibaba cloud

C语言力扣第61题之旋转链表。双端队列与构造循环链表

RMAN do not mark expired backups

基于STM32和阿里云的环境检测系统设计

通过js来实现一元二次方程的效果,输入a,b,c系数后可计算出x1和x2的值

12.优先级队列和惰性队列
随机推荐
Methods of using multiple deformations on an element
Common components of solder pad (2021.4.6)
Shielding ODBC load balancing mode in gbase 8A special scenarios?
安装ros的laser_scan_matche库所遇到的问题(一)
The structure pointer must be initialized, and the pointer must also be initialized
Semantic segmentation correlation
How to set the SQL execution timeout for flick SQL
STM32F103ZET6程序移植为C8T6+C8T6下载程序flash timeout的解决方案
12.优先级队列和惰性队列
数据源是SQL server ,我要配置日期字段 updateDate 最后两天日期的增量数据,做增
基于STM32和阿里云的环境检测系统设计
Install the laser of ROS_ scan_ Problems encountered in match library (I)
[untitled]
通过js来实现一元二次方程的效果,输入a,b,c系数后可计算出x1和x2的值
全屋WiFi方案:Mesh路由器组网和AC+AP
There is a special cryptology language called asn.1
[k210 stepping pit] pytorch model is converted to kmodel and used on dock. (ultimately not achieved)
SQL server当存储过程接收的参数是int类型时,如何做判断?
flink-sql 如何设置 sql执行超时时间
大佬们flink的JDBC SQL Connector现在不支持所有的数据库吗,例如vertica?