0

在下面的代码中,_model.BasicConsume 在通过 consumer.received 事件接收到的消息得到消息之前被调用。因此,它从事件触发中清除所有队列项,然后异步触发稍后的事件。如何确保只有通过事件触发器接收到的项目才被队列一一消费,而不是一起消费?

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();
        }
4

0 回答 0