Rabbitmq使用.NET使用单个同步调用检索多条消息 [英] Rabbitmq retrieve multiple messages using single synchronous call using .NET

查看:58
本文介绍了Rabbitmq使用.NET使用单个同步调用检索多条消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以通过使用.NET的单个同步调用来接收多条消息?
我已经看到问题,并且找到了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使用单个同步调用检索多条消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆