With RabbitMQ is there a way to use it similar to MSSMQ where one can pop 1000 messages from the queue, then do your inserts to the database and continue from there.
I cannot seem to do that with a Subscription to a channel and then doing a foreach over the BasicDeliveryEventArgs in the Subscription, with that doing a If statement with the max message count I want to process at the given time.
Thanks in advance This however still takes all 22k messages from the queue
using (IConnection connection = factory.CreateConnection())
{
using (IModel channel = connection.CreateModel())
{
channel.QueueDeclare("****", true, false, false, null);
var subscription = new Subscription(channel, "****", false);
int maxMessages = 5;
int i = 0;
foreach (BasicDeliverEventArgs eventArgs in subscription)
{
if (++i == maxMessages)
{
Console.WriteLine("Took 5 messages");
subscription.Ack(eventArgs);
break;
}
}
}
}