有没有办法使用 .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 使用单个同步调用检索多条消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!