Rabbitmq retrieve multiple messages using single synchronous call using .NET(Rabbitmq 使用 .NET 使用单个同步调用检索多条消息)
问题描述
有没有办法使用 .NET 使用单个同步调用来接收多条消息?
我看过 question 并且找到了 java 类com.rabbitmq.client.QueueingConsumer,但是我在.NET 命名空间(RabbitMQ.Client、RabbitMQ.Client.Events)中没有找到这样的客户端类
Is there a way to receive multiple message using a single synchronous call using .NET?
I've seen question and I've found java class com.rabbitmq.client.QueueingConsumer, but I haven't found such client class in .NET namespaces (RabbitMQ.Client, RabbitMQ.Client.Events)
推荐答案
您可以使用 BasicQoS.PrefetchCount 检索任意数量的消息:
You can retrieve as many messages as you want using the BasicQoS.PrefetchCount:
var model = _rabbitConnection.CreateModel();
// Configure the Quality of service for the model. Below is how what each setting means.
// BasicQos(0="Dont send me a new message untill I’ve finshed", _fetchSize = "Send me N messages at a time", false ="Apply to this Model only")
model.BasicQos(0, fetchSize, false);
注意:如果您设置 fetchSize = 20,那么它将检索当前在队列中的前 20 条消息.但是,一旦队列被清空,它不会等待 20 条消息在队列中建立,它会尽快开始消耗它们,最多一次 20 个.
Note: if you set fetchSize = 20 then it will retrieve the first 20 messages that are currently in the queue. But, once the queue has been emptied it won't wait for 20 messages to build up in the queue, it will start consuming them as fast as possible, grabbing up to 20 at a time.
希望这是有道理的.
这篇关于Rabbitmq 使用 .NET 使用单个同步调用检索多条消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Rabbitmq 使用 .NET 使用单个同步调用检索多条消息
基础教程推荐
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
