标题 :

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();

}

}

}

![](https://www.showdoc.cc/server/api/common/visitfile/sign/56914cf30a2ac84904c2fa431b727b97?showdoc=.jpg)
在上代码中,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的更多相关文章

  1. [LeetCode] Implement Stack using Queues 用队列来实现栈

    Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...

  2. Ring buffers and queues

    Ring buffers and queues The data structure is extremely simple: a bounded FIFO. One step up from pla ...

  3. RabbitMQ官方中文入门教程(PHP版) 第二部分:工作队列(Work queues)

    工作队列 在第一篇教程中,我们已经写了一个从已知队列中发送和获取消息的程序.在这篇教程中,我们将创建一个工作队列(Work Queue),它会发送一些耗时的任务给多个工作者(Works ). 工作队列 ...

  4. 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 ...

  5. RabbitMQ(二) -- Work Queues

    RabbitMQ(一) -- Work Queues RabbitMQ使用Work Queues的主要目的是为了避免资源使用密集的任务,它不同于定时任务处理的方式,而是把任务封装为消息添加到队列中.而 ...

  6. Implement Stack using Queues

    Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...

  7. the OS maintains a number of queues

    COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION To do its job, the OS ...

  8. (leetcode)Implement Stack using Queues

    Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...

  9. iOS 并发编程之 Operation Queues

    现如今移动设备也早已经进入了多核心 CPU 时代,并且随着时间的推移,CPU 的核心数只会增加不会减少.而作为软件开发者,我们需要做的就是尽可能地提高应用的并发性,来充分利用这些多核心 CPU 的性能 ...

  10. (easy)LeetCode 225.Implement Stack using Queues

    Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...

随机推荐

  1. CTFHub - Web(六)

    命令注入: 1.进入页面,测试127.0.0.1, 关键代码: <?php $res = FALSE; if (isset($_GET['ip']) && $_GET['ip'] ...

  2. Oracle备份审计表SYS.AUD$和SYS.FGA_LOG$

    ORACLE的审计表不可以使用expdp和impdp导出和导入,如果使用,会报如下错误: 需要使用exp和imp进行导出和导出 导出语句: exp " '/ as sysdba' " ...

  3. C#实现一个弹窗监控小程序

    一..实现弹窗淡入淡出等效果即弹窗自动关闭 技术要点: 1.弹窗效果(淡入淡出,自下而上滑入)使用WIN API实现 2.弹出的窗体在一定时间后,自动关闭使用一个timer实现,弹窗开始是,打开tim ...

  4. centos6-centos7防火墙(iptables-firewalld)设置端口nat转发

    背景: 将本机的 8080端口转发至其他主机,主机 IP:192.168.1.162,目标主机 IP和端口192.168.1.163:80,方法如下: centos6系统iptables环境下: ip ...

  5. 【Azure Developer】在Azure Resource Graph Explorer中查看当前订阅下的所有资源信息列表并导出(如VM的名称,IP地址内网/公网,OS,区域等)

    问题描述 通过Azure的Resource Graph Explorer(https://portal.azure.cn/#blade/HubsExtension/ArgQueryBlade),可以查 ...

  6. 浅谈自动化构建之gulp

    一.gulp的基本使用 gulp是目前最流行的前端自动化构建系统,核心特点高效易用.(这块不过多的废话了,直接上干货了,有兴趣的话,可以查下gulp简介) 步骤如下: yarn init -y yar ...

  7. JetBrains(IEDA、CLion、Pycharm) 学生获得免费使用资格

    JetBrains针对学生推出了免费使用资格,但是很多同学却不知道或者说不知道怎样获得免费资格,只能千辛万苦的去寻找破解密钥,但现在JetBrains针对盗版的封锁越来越严密,很多密钥过一段时间就会失 ...

  8. HTTPS是怎么保证数据安全传输的?

    前言 关于HTTPS的连接过程,也是老生常谈的话题了. 其中涉及到的数字证书.电子签名.SSL/TLS.对称加密.非对称加密的问题总是让人摸不清头脑,不知道怎么回答. 今天就和大家再熟悉熟悉这其中千丝 ...

  9. js异步、事件循环(EventLoop)小结

    单线程 众所周知,JS是单线程的语言,之所以是单线程,用一句烂大街的话就是,如果两个线程同时操作一个DOM节点,那么该以哪个为准呢,虽然多线程也有办法解决,但是js毕竟是浏览器脚本语言,不需要那么复杂 ...

  10. Spring框架——JDBC方式搭建项目

    学习Spring框架,使用JDBC的方式配置方式搭建一个项目,进行项目总结. 首先,采用MVC设计模式思想,搭建项目目录. 然后各个目录文件下面的相关源码附上: controller目录: impor ...