3.Work Queues
标题 :
3.Work Queues
目录 :
RabbitMQ
序号 :
3
var channel1 = _connection.CreateModel();
channel1.BasicQos(0, 1, false);
channel1.QueueDeclare(queue: "hello",
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
var consumer = new EventingBasicConsumer(channel1);
consumer.Received += (model, ea) =>
{
var body = ea.Body;
var message = Encoding.UTF8.GetString(body);
Console.WriteLine(" [x] Received {0} From consumer1 " +DateTime.Now, message);
Thread.Sleep(300);
channel1.BasicAck(ea.DeliveryTag, false);
};
channel1.BasicConsume(queue: "hello", false, consumer: consumer);
var channel2 = _connection.CreateModel();
channel2.BasicQos(0, 1, false);
channel2.QueueDeclare(queue: "hello",
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
var consumer2 = new EventingBasicConsumer(channel2);
consumer2.Received += (model, ea) =>
{
var body = ea.Body;
var message = Encoding.UTF8.GetString(body);
Console.WriteLine(" [x] Received {0} From consumer2 " + DateTime.Now, message);
Thread.Sleep(1000);
channel2.BasicAck(ea.DeliveryTag,false);
};
channel2.BasicConsume(queue: "hello", false, consumer: consumer2);
Console.WriteLine(" Press [enter] to exit.");
Console.ReadLine();
}
}
}

在上代码中,consumer1的消费能力高,consumer2的消费能力低.在我们设定好Qos和手动确认后,两个consumer的消费比例大约是3:1而不在是之前的1:1
###引用链接
https://fanyi.baidu.com/translate?aldtype=16047&query=&keyfrom=baidu&smartresult=dict&lang=auto2zh#auto/zh/
https://www.throwable.club/2018/11/28/rabbitmq-extension-consumer-prefetch/#%E6%B6%88%E8%B4%B9%E8%80%85%E6%B6%88%E6%81%AF%E9%A2%84%E8%AF%BB%E5%8F%96
3.Work Queues的更多相关文章
- [LeetCode] Implement Stack using Queues 用队列来实现栈
Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...
- Ring buffers and queues
Ring buffers and queues The data structure is extremely simple: a bounded FIFO. One step up from pla ...
- RabbitMQ官方中文入门教程(PHP版) 第二部分:工作队列(Work queues)
工作队列 在第一篇教程中,我们已经写了一个从已知队列中发送和获取消息的程序.在这篇教程中,我们将创建一个工作队列(Work Queue),它会发送一些耗时的任务给多个工作者(Works ). 工作队列 ...
- Java for LeetCode 225 Implement Stack using Queues
Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...
- RabbitMQ(二) -- Work Queues
RabbitMQ(一) -- Work Queues RabbitMQ使用Work Queues的主要目的是为了避免资源使用密集的任务,它不同于定时任务处理的方式,而是把任务封装为消息添加到队列中.而 ...
- Implement Stack using Queues
Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...
- the OS maintains a number of queues
COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION To do its job, the OS ...
- (leetcode)Implement Stack using Queues
Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...
- iOS 并发编程之 Operation Queues
现如今移动设备也早已经进入了多核心 CPU 时代,并且随着时间的推移,CPU 的核心数只会增加不会减少.而作为软件开发者,我们需要做的就是尽可能地提高应用的并发性,来充分利用这些多核心 CPU 的性能 ...
- (easy)LeetCode 225.Implement Stack using Queues
Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...
随机推荐
- python—base64
今天在写题时,执行脚本又报错了 脚本如下 #! /usr/bin/env python3 # _*_ coding:utf-8 _*_ import base64 # 字典文件路径 dic_file_ ...
- EXPORT和IMPORT使用示例
1 report ztestprog. 2 data:begin of itab1 occurs 0, 3 ff(10), 4 end of itab1. 5 data:itab2 like itab ...
- Spring Boot(IDEA,Gradle)超详细用户管理项目(一)——Hello World
1.构建工具的配置(Gradle):自定义-所有设置:构建.执行.部署-构建工具-Gradle: 设置Gradle用户主目录:(该目录相当于仓库,gradle将下载所需依赖到此目录下),此目录下可新建 ...
- Java 8中字符串拼接新姿势:StringJoiner
介绍 StringJoiner是java.util包中的一个类,用于构造一个由分隔符分隔的字符序列(可选),并且可以从提供的前缀开始并以提供的后缀结尾.虽然这也可以在StringBuilder类的帮助 ...
- python 编译EXE文件
以labelme测试 标注工具labelimg和labelme 矩形标注工具:labelimg 多边形标准工具:labelme 前者官网发布了可执行文件,后者只有python源码,如果需要编译wind ...
- 浅谈java中线程和操作系统线程
在聊线程之前,我们先了解一下操作系统线程的发展历程,在最初的时候,操作系统没有进程线程一说,执行程序都是串行方式执行,就像一个队列一样,先执行完排在前面的,再去执行后面的程序,这样的话很多程序的响应就 ...
- javascript通过递归改子节点数据-用于层级深度未知的树形结构
最近在做这么个需求:树形结构,层级深度未知,一旦某个节点的状态是置灰的话,其所有子节点都要置灰. 方案一(数据库有值):如果数据库里置灰节点的所有子节点,值也都是"置灰",那后台取 ...
- (09)-Python3之--类的三大特性(封装、继承、多态)
1.封装 封装,就是只能在类的内部访问,外部访问属性或方法会报异常,python中的封装很简单,只要在属性前或者方法名前加上两个下划线就可以,如self.__name,def __eat(self)这 ...
- Tensorflow-交叉熵&过拟合
交叉熵 二次代价函数 原理 缺陷 假如我们目标是收敛到0.A点为0.82离目标比较近,梯度比较大,权值调整比较大.B点为0.98离目标比较远,梯度比较小,权值调整比较小.调整方案不合理. 交叉熵代价函 ...
- mysql事务测试
mysql事务测试 打开mysql的命令行,将自动提交事务给关闭 --查看是否是自动提交 1表示开启,0表示关闭 select @@autocommit; --设置关闭 set autocommit ...