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数据结构 - chap9 排序
			
判断题: 选择题: 编程题: 7-1 排序: 输入样例: 11 4 981 10 -17 0 -20 29 50 8 43 -5 输出样例: -20 -17 -5 0 4 8 10 29 43 50 ...
 - 使用yaml来实现ingress-nginx
			
创建一个ingress-nginx [root@k8s-master ingress]# cat ingress-nginx.yaml apiVersion: v1 kind: Namespace m ...
 - Java运算符概要与数学函数
			
运算符概要 在Java中,使用算术运算符+,-,*,/表示加减乘除运算,当参与/的运算的两个操作数都是整数时,表示整数除法,否则,表示浮点除法.整数的求余操作(有时称为取模),用%表示,例如,15/2 ...
 - Redis 实战 —— 04. Redis 数据结构常用命令简介
			
字符串 P39 Redis 的字符串是一个有字节组成的序列,可以存储以下 3 种类型的值:字节串(byte string).整数.浮点数. 在需要的时候, Redis 会将整数转换成浮点数.整数的取值 ...
 - 特斯拉Toolbox诊断检测仪工具Tesla诊断电脑 Tesla Toolbox
			
Tesla特斯拉Toolbox诊断工具Tesla诊断电脑检测仪 Tesla Toolbox, Tesla Toolbox Diagnostic Tester.Language: English,Deu ...
 - [CPP] STL 简介
			
STL 即标准模板库(Standard Template Library),是 C++ 标准库的一部分,里面包含了一些模板化的通用的数据结构和算法.STL 基于模版的实现,因此能够支持自定义的数据结构 ...
 - 我为什么不鼓吹 WireGuard
			
原文链接:https://fuckcloudnative.io/posts/why-not-wireguard/ 最近有一款新型 VPN 工具备受瞩目,相信很多人已经听说过了,没错就是 WireGua ...
 - 记一次压测问题定位:connection reset by peer,TCP三次握手后服务端发送RST_网络_c359719435的专栏-CSDN博客 https://blog.csdn.net/c359719435/article/details/80300433
			
记一次压测问题定位:connection reset by peer,TCP三次握手后服务端发送RST_网络_c359719435的专栏-CSDN博客 https://blog.csdn.net/c3 ...
 - loj10012 Best Cow Fences
			
题目描述 原题来自:USACO 2003 Mar. Green 给定一个长度为 N 的非负整数序列 A ,求一个平均数最大的,长度不小于 L 的子段. 输入格式 第一行用空格分隔的两个整数 N 和 L ...
 - LOJ10145郁闷的出纳员
			
传送门:https://loj.ac/problem/10145 简单的平衡树 ------------------------------------ 1 #include<bits/stdc ...