Regression using DotNet RabbitMQ.Client version=6.2.4

19 views
Skip to first unread message

Tesar Smartwatch

unread,
Nov 18, 2022, 9:09:24 AM11/18/22
to rabbitmq-users

I'm using RabbitMQ.Client inside many projects in .Net Framework 4.7.2. 

Using the versions 5.X.X of the client was possible to wait incoming messages with simple code like this:

const string EXCHANGE_NAME = "EXCHANGE3"; ConnectionFactory factory = new ConnectionFactory(); IConnection connection = factory.CreateConnection()) IModel channel = connection.CreateModel()) channel.ExchangeDeclare(EXCHANGE_NAME, ExchangeType.Topic, false, true, null); string queueName = channel.QueueDeclare(); EventingBasicConsumer consumer = new EventingBasicConsumer(channel); consumer.Received += (o, e) => { string data = Encoding.ASCII.GetString(e.Body); Console.WriteLine("received: " + data); Thread.Sleep(1000); Console.WriteLine("done."); }; string consumerTag = channel.BasicConsume(queueName, true, consumer); channel.QueueBind(queueName, EXCHANGE_NAME, "myTopic");

Now, with version 6.2.4, you need to append a line with Console.ReadLine() otherwise the application closes.

This is blocking because: all previous windows services, listening for messages and created by the library System.ServiceProcess.ServiceBase, closes immediately after start. 

Luke Bakken

unread,
Nov 18, 2022, 10:08:51 AM11/18/22
to rabbitmq-users
Hello,

Yes, this is intended behavior, and technically not a regression because the major version change from "5" to "6" allows for it.

You need to modify your code to not exit early. I suggest using something like ManualResetEvent and waiting on that, which is a common pattern in something long-running like a windows service. Whatever part of your application that is responsible for shutting down can signal that event, and you can clean up your RabbitMQ consumer and other resources at that point.

Thanks,
Luke

Reply all
Reply to author
Forward
0 new messages