无法收到已发布的消息

时间:2016-11-05 13:24:18

标签: rabbitmq

我已经在我的开发机器中创建了本地Rabbit MQ Server,创建了Queue Exchange和Routing Key来接收消息。下面是我的接收者代码。

string MQUrl = "amqp://<userName>:<Password>@10.251.74.64:5672/guest";
ConnectionFactory conFactory = new ConnectionFactory();
conFactory.Uri = MQUrl;
using (var connection = conFactory.CreateConnection())
{
    Console.WriteLine("MQ Connection Created");
    using (var channel = connection.CreateModel()) { }
} 

channel.ExchangeDeclare(exchange: "dotnet.build.fanout.exchange", type: ExchangeType.Fanout, durable: true, autoDelete: false, arguments: null);
            var queueName = channel.QueueDeclare().QueueName;
            Console.WriteLine("Queue Name is " + queueName);
            channel.QueueBind(queue: queueName, exchange: "dotnet.build.fanout.exchange", routingKey: "dotnet.build.fanout.queue");

            var consumer = new EventingBasicConsumer(channel);
            consumer.Received += (model, ea) =>
            {
                var body = ea.Body;
                Console.WriteLine("The Message is:" + Encoding.UTF8.GetString(body));
            };
            channel.BasicConsume(queue: queueName,
                     noAck: false,
                     consumer: consumer);

我正在从Rabbit MQ Web Console发布消息。但我无法在控制台中打印消息。甚至消息也没有得到承认。

0 个答案:

没有答案