Processing a Batch of IMessage's

Is there a way for a service to poll the MQ broker and read multiple requests if the queue depth is long? This would greatly simplify a lot of our code where we need to batch up requests to another API but the producers are best suited to messaging.

Something like this working would be amazing:

    public class testq
    {

    }

    public object Any(testq req)
    {
        Console.WriteLine("Single Called");

        System.Threading.Thread.Sleep(1000);
        return new HttpResult() { StatusCode = System.Net.HttpStatusCode.NoContent };


    }

    public object Any(testq[] req)
    {

        Console.WriteLine("Batch Called");
        return new HttpResult() { StatusCode = System.Net.HttpStatusCode.NoContent };

    }

    public object Any(fooReq req)
    {

        for(var i=0;i<9999;i++)
        {
            Gateway.Publish(new testq());
        }
     return "";
    }

No that feature doesn’t exist.

You could rewrite your Service so it batches Request DTOs until it reaches a user-defined limit than calls your testq[] Service. Note that when your Service persists the message it acknowledges receipt and removes it from the MQ so if you have a failure “mid-batch” you could lose messages.

Ok thanks. We do have an existing pattern that creates a secondary queue or stack for batching but it is cumbersome to manage the tail of the stream of requests, you have to have the publisher signal the end which is goofy. Perhaps I will go after a combination of polling and triggering from the single requests.

If you need to pass additional metadata to the service you can use the IRequest.Items collection.