Bulk-fetching messagesΒΆ

There are times where it is easier to fetch a bunch of messages and process them in a bulk operation, rather than having an active subscriber that processes the messages as they come. This is not part of the core functionality of RawRabbit, but exists as a client extension from the RawRabbit.Extensions package.

Getting started with the extensions are easy. Create an bus client using the RawRabbitFactory.GetExtendableClient() method. That’s it - you’re ready to bulk fetch!

var bulk = client.GetMessages(cfg => cfg
    .ForMessage<BasicMessage>(msg => msg
        .FromQueues("first_queue", "second_queue")
    .ForMessage<SimpleMessage>(msg => msg

The fluent builder lets specify what message type you are interested in retrieving, from what queues and how large the batch should be. If you want to get all messages, simple use GetAll() and it will empty the queues.

The result contains method for getting messages by type. You can decide for each message if you want to Ack it, Nack it or put it back in the queue again.

var basics = bulk.GetMessages<BasicMessage>()
foreach (var message in basics)
    if (CanBeProcessed(message))
        // do stuff

If you feel like performing Ack/Nack the entire bulk, that’s fine too


Learn more and try it out yourself by running the BulkGetTests.cs