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 ...
随机推荐
- oracle常见进度查询脚本
1.查看索引创建进度 /* Formatted on 2019/8/20 下午 05:08:25 (QP5 v5.163.1008.3004) */ SELECT SID, DECODE (total ...
- Electron入门Demo之桌面应用计算器笔记(二)
码文不易啊,转载请带上本文链接呀,感谢感谢 https://www.cnblogs.com/echoyya/p/14307996.html 在之前总结了一篇自学笔记,通过之前学习到的方法和知识,完成了 ...
- Python编程小技巧(一)
在使用Tkinter编写代码的时候,有时候会忘记某个组件的参数是什么或者忘记某个参数怎么拼写的,此时可以通过如下方式查询组件的参数列表,以按钮组件为例: 1 # -*- coding:utf-8 -* ...
- DC-DC变换器,24v转5v稳压芯片,3A输出电流
在24V输入中,比较合适的LDO可以选择:PW6206,输出电压3V,3.3V,5V 输入电压最高40V,功耗也低4uA左右,采用SOT23-3封装. PW6206系列是一个高精度,高输入电压低静态电 ...
- Effective Java, 3e阅读笔记一
引言 本书的目标是帮助读者更加有效地使用Java编程语言及其基本类库,适用于任何具有实际Java工作经验的程序员. 本书一共90个条目,12章,每个条目讨论一条规则,这些规则反映了最有经验的优秀程序员 ...
- java虚拟机入门(一)-jvm基础
转行学java之前,总是听着大佬们说着java像个渣男一样可以跨平台,一次编译到处运行,瞬间,我就坚定了学java的信念,哎呀妈呀,得劲.真的学java之后,好像渣男也不是那么好学的,尤其这货的必杀技 ...
- Navicat 创建mysql存过、定时执行存过
创建存过: 使用Navicat for MySQL工具创建存储过程步骤: 1. 新建函数(选择函数标签 -> 点击新建函数): 2.输入函数的参数个数.参数名.参数类型等: 3.编写存储过程: ...
- 键相同,比较两个map中的值是否相同
获取.排序.比较两个Map中相同key对应value值 /** * * @param hashMap 原数据 * @param hashMap2 需要比较的数据 * @return */ privat ...
- py, pyc, pyw, pyo, pyd Compiled Python File (.pyc) 和Java或.NET相比,Python的Virtual Machine距离真实机器的距离更远
https://my.oschina.net/renwofei423/blog/17404 1. PyCodeObject与Pyc文件 通常认为,Python是一种解释性的语言,但是这种说法 ...
- Golang--Directional Channel(定向通道)
Directional Channel 通道可以是定向的(directional).在默认情况下,通道将以双向的(bidirectional)形式运作,用户既可以把值放人通道,也可以从通道取出值;但是 ...