admin管理员组文章数量:1125738
I am hoping to use EasyNetQ for a consumer task where I will read a batch of messages (say 100) from one or more RabbitMQ queues, and process batches upstream. I don't want to Ack
the messages until the upstream process completes , because if my process crashes while the upstream is happening, I'd like the messages to not get dropped.
My test code at the moment looks like (pseudocode - have omitted synchronization detail and so on):
var bus = RabbitHutch.CreateBus("host=localhost");
var consumer = bus.Advanced.Consume(queue, (body, properties, info) =>
{
MessageHandler(body, properties, info);
});
// ...
static void MessageHandler(ReadOnlyMemory<byte> content, MessageProperties props, MessageReceivedInfo info)
{
messageBatch.Add((content, info));
if (messageBatch.Count >= 100)
// trigger another thread to do batch processing
}
The default behaviour of EasyNetQ is that the bus.Advanced.Consume
function does an Ack
as soon as the handler function returns. Is it possible to turn that off, and if so, then what function can I call to send the Acks later on?
NB. RabbitMQ Consume Messages in Batches and Ack them all at once addresses this question for RabbitMQ.Client
, but I would like to know if it's possible in the EasyNetQ
client.
I am hoping to use EasyNetQ for a consumer task where I will read a batch of messages (say 100) from one or more RabbitMQ queues, and process batches upstream. I don't want to Ack
the messages until the upstream process completes , because if my process crashes while the upstream is happening, I'd like the messages to not get dropped.
My test code at the moment looks like (pseudocode - have omitted synchronization detail and so on):
var bus = RabbitHutch.CreateBus("host=localhost");
var consumer = bus.Advanced.Consume(queue, (body, properties, info) =>
{
MessageHandler(body, properties, info);
});
// ...
static void MessageHandler(ReadOnlyMemory<byte> content, MessageProperties props, MessageReceivedInfo info)
{
messageBatch.Add((content, info));
if (messageBatch.Count >= 100)
// trigger another thread to do batch processing
}
The default behaviour of EasyNetQ is that the bus.Advanced.Consume
function does an Ack
as soon as the handler function returns. Is it possible to turn that off, and if so, then what function can I call to send the Acks later on?
NB. RabbitMQ Consume Messages in Batches and Ack them all at once addresses this question for RabbitMQ.Client
, but I would like to know if it's possible in the EasyNetQ
client.
1 Answer
Reset to default 0From checking the project source, this subject is partially addressed by an undocumented class PullingConsumer
:
- Pulling consumer #1073
which includes methods
PullAsync
,AckAsync
,RejectAsync
(works with 1 message at a time)PullBatchAsync
,AckBatchAsync
,RejectBatchAsync
(works with batches of a size that you specify)
The limitations are:
PullingConsumer
can only listen on a single queue at a time (i.e. no wait on multiple queues -- you'd need one of these per queue)
The batch functions don't support partial batches but I think partial batches could be handled by doing PullAsync
and then when something is received, try a PullBatchAsync(n-1, ...
with a very short timeout.
本文标签: cManual Ack in EasyNetQis it possibleStack Overflow
版权声明:本文标题:c# - Manual Ack in EasyNetQ, is it possible? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736674353a1947099.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论