Reputation: 55032
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
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