0

In the code below, _model.BasicConsume is called before the messages received via consumer.received event gets the message. So it clears all the queue items from the event is triggered and then later event is triggered asynchronously. How can I make sure that only items received via event trigger are consumed by the queue one by one instead of all together?

public  static void ReceiveMessages()
        {
            var consumer = new RabbitMQ.Client.Events.EventingBasicConsumer(_model);

            Console.WriteLine(" [*] Waiting for messages...");

            consumer.Received += (Payment, ea) =>
            {               
                var body = ea.Body;
                var message = (Payment)body.ToArray().DeSerialize(typeof(Payment));                
                Console.WriteLine($"Message is : {message.CardNumber} : {message.Name} : {message.Amount}");
            };

            _model.BasicConsume(QueueName, true, consumer);

            Console.WriteLine(" Press enter to exit...");
            Console.ReadLine();
        }
Kara Kartal
  • 249
  • 1
  • 2
  • 8
  • 1
    What makes you think they're all be consumed at the same time? – David L Apr 21 '20 at 21:04
  • When I check the RabbitMQ management console, I can see that all the items are consumed but the output to console is written much later. What I want to see that items are consumed on the server right after the console output is written one by one. Hope it makes sense. – Kara Kartal Apr 21 '20 at 21:40
  • @KaraKartal read the documentation about channel prefetch / QoS. – Luke Bakken Apr 23 '20 at 02:07

0 Answers0