开发者

RabbitMQ - Not able to get sets of messages in the same order

开发者 https://www.devze.com 2023-01-03 09:40 出处:网络
I am using Rabbit MQ in C#. This is my scenario A separate process publishes messages to the queue Client has to read set of N messages from queue

I am using Rabbit MQ in C#. This is my scenario

  1. A separate process publishes messages to the queue
  2. Client has to read set of N messages from queue
  3. Process the N messages
  4. Acknowledge the N messages

Under the same channel, I receive the messages and then process them and then acknowledge them. The server process keeps publishing messages. The problem I am facing is, when I try to get next set of messages, they do not come in the same order as it was published by the publishing process. The messages come in a random order. Only the first set of messages come in the correct order.

Does any one what is going wrong here? Is creating a new channel to access the next set of messages not right? Below is the sample code:

while (true)
         {
             using (IModel getChannel = MQConnection.CreateModel())
             {
                 // Create a consumer
                 QueueingBasicConsumer consumer = CreateQueueConsumer(getChannel, exchangeName, queueName);

                 int numberOfMessages = 100;
                 // Next开发者_如何学Python Recieve
                 List<object> msgSet = GetNextSetOfMessages(consumer, getChannel, exchangeName, queueName, numberOfMessages, out finalDeliverytag);


                 // Do some processing

                 if (finalDeliverytag > 0)
                     AckFinishedMessages(exchangeName, queueName, finalDeliverytag, getChannel);

                 if (finalDeliverytag == 0)
                     break;

             }
         }

Kindly help. Thanks!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号