RabbitMQ c#客户端异步支持

时间:2012-08-18 23:06:50

标签: c# asynchronous rabbitmq

我有这段代码,我使用rabbitmq client。我很好奇这是异步还是同步?如果是同步的,我怎么能让它异步?

        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);

            }

        }

1 个答案:

答案 0 :(得分:1)

official C# client guide的第2.9章:

  

应用程序回调处理程序不得调用阻止AMQP操作(例如   IModel.QueueDeclare,IModel.BasicCancel或IModel.BasicPublish)。如果他们这样做,该频道将陷入僵局

BasicPublish是imho阻止同步操作。