我使用以下代码将原始消息发布到队列:
using (var bus = RabbitHutch.CreateBus("host=myserver;virtualHost=myhost;username=xxx;password=yyy").Advanced)
{
var queue = bus.QueueDeclare("MyQueue");
var exchange = bus.ExchangeDeclare("MyExchange", ExchangeType.Topic);
var binding = bus.Bind(exchange, queue, "");
var properties = new MessageProperties();
var body = System.Text.Encoding.UTF8.GetBytes("This is the body of the message");
bus.Publish(exchange, "", false, false, properties, body);
}
消息已传递到队列,我在RabbitMQ控制台的队列中看到一条消息。但是,当我尝试使用以下代码消费它时,我没有得到任何回报:
bus.Consume(queue, (body, properties, info) => Task.Factory.StartNew(() =>
{
var message = Encoding.UTF8.GetString(body);
Console.Out.WriteLine("Got message: '{0}'", message);
}));
我可以看到该消息是从Rabbit的控制台发送的,但没有任何内容打印出来,消息仍然在队列中。我错过了什么?