1

我使用以下代码将原始消息发布到队列:

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 的控制台传递的,但没有打印出来,消息仍在队列中。我错过了什么?

4

0 回答 0