Rabbitmq 使用 .NET 使用单个同步调用检索多条消息

Rabbitmq retrieve multiple messages using single synchronous call using .NET(Rabbitmq 使用 .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 使用单个同步调用检索多条消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)