DarthVader
DarthVader

Reputation: 55032

RabbitMQ c# client asynchrony support

I have this piece of code and i use rabbitmq client. i m curious if this is asynchronous or synchronous? if synchronous, how can i make it async ?

        ConnectionFactory factory = new ConnectionFactory();
        factory.HostName = "localhost";
        using (IConnection connection = factory.CreateConnection())
        using (IModel channel = connection.CreateModel())
        {
            channel.QueueDeclare("hello", false, false, false, null);
            for (int i = 0; i < 1000; i++)
            {
                string message = "Hello World!";
                byte[] body = System.Text.Encoding.UTF8.GetBytes(message);

                channel.BasicPublish("", "hello", null, body);

            }

        }

Upvotes: 2

Views: 3979

Answers (1)

Michal Lev&#253;
Michal Lev&#253;

Reputation: 37793

See chapter 2.9 of official C# client guide:

Application callback handlers must not invoke blocking AMQP operations (such as IModel.QueueDeclare, IModel.BasicCancel or IModel.BasicPublish). If they do, the channel will deadlock

BasicPublish is imho blocking synchronous operation.

Upvotes: 1

Related Questions