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 ...
随机推荐
- SDUST数据结构 - chap4 串
函数题: 6-1 查找子串: 裁判测试程序样例: #include <stdio.h> #define MAXS 30 char *search(char *s, char *t); vo ...
- ctfhub技能树—信息泄露—备份文件下载—.DS_Store
打开靶机 查看页面信息 使用dirsearch进行扫描 访问该网页,下载文件 使用Linux系统打开文件 发现一个特殊文件,使用浏览器打开 拿到flag 二.使用Python-dsstore工具查看该 ...
- SpringBoot WebSocket技术
最近看了Spring in Action,了解了一下WebSocket和Stomp协议相关技术,并搭建了一个项目.网上的例子不完整或者描述不清,所以自己记录一下以作备忘. 一.配置 Spring Bo ...
- ASP.NET Core错误处理中间件[3]: 异常处理器
DeveloperExceptionPageMiddleware中间件错误页面可以呈现抛出的异常和当前请求上下文的详细信息,以辅助开发人员更好地进行纠错诊断工作.ExceptionHandlerMid ...
- javascript判断浏览器访问,刷新,返回
话不多说,直接上 if (window.performance.navigation.type === 0/* 正常访问 */) { // 你要干的事 } else if (window.perfor ...
- requests模块的基本使用
requests模块的基本使用 基于网络请求的模块. 环境的安装:pip install requests 作用:模拟浏览器发起请求 分析requests的编码流程: 1.指定url 2.发起了请求 ...
- JavaScript中创建对象的三种方式!
JavaScript中创建对象的三种方式! 第一种 利用对象字面量! // 创建对象的三种方式! // 1 对象字面量. var obj = { // 对象的属性和方法! name: 'lvhang' ...
- 浅析Linux进程空间布局
一.进程空间分布概述 对于一个进程,其空间分布如下图所示: 1.参数说明 程序段(Text):程序代码在内存中的映射,存放函数体的二进制代码. 初始化过的数据(Data):在程序运行初已经对变量进行初 ...
- vercel是什么神仙网站?
Vercel? vercel是我用过的最好用的网站托管服务.本网站就是基于hexo引擎模板开发,托管在vercel上的. vercel类似于github page,但远比github page强大,速 ...
- Java面向对象(一)----初次见面
面向对象 面向过程:根据业务逻辑从上到下写代码 函数式编程:对一些功能的代码封装到函数中,日后无需重复编写,直接调用函数就可以了 面向对象:将所有的功能进行封装,面对的事封装了功能的实体(对象),即面 ...