首页新闻找找看学习计划

RabbitMQ无法接收消息的问题

0
悬赏园豆:5 [已解决问题] 解决于 2019-09-11 14:39

目前遇到一个RabbitMQ无法接收消息的问题,问题如下:
发送端代码:

        var factory = new ConnectionFactory();
        factory.HostName = "localhost";
        factory.UserName = "station";
        factory.Password = "123456-a";

        using (var connection = factory.CreateConnection())
        {
            using (var channel = connection.CreateModel())
            {
                var properties = channel.CreateBasicProperties();
                properties.Persistent = true;

                channel.QueueDeclare("20-x:device-message", true, false, false, null);
                var body = Encoding.UTF8.GetBytes(message);
                channel.BasicPublish("", "20-x:device-message", properties, body);
            }
        }

消息发送成功。

接收端代码:

        var factory = new ConnectionFactory();
        factory.HostName = "localhost";
        factory.UserName = "station";
        factory.Password = "123456-a";

        using (var connection = factory.CreateConnection())
        {
            using (var channel = connection.CreateModel())
            {
                var consumer = new EventingBasicConsumer(channel);

                consumer.Received += (model, ea) =>
                {
                    var body = ea.Body;
                    var messageText = Encoding.UTF8.GetString(body);

                    //var message = JsonConvert.DeserializeObject<ICreateMessageDto>(messageText);

                    //channel.BasicAck(ea.DeliveryTag, true);
                };
                channel.BasicConsume("20-x:device-message", false, consumer);
            }
        }

var messageText = Encoding.UTF8.GetString(body);
这行代码一直无法触发。

多啦A梦的弟弟的主页 多啦A梦的弟弟 | 初学一级 | 园豆:44
提问于:2019-09-10 21:48
< >
分享
最佳答案
0

RabbitMQ 后台管理界面,看看有没有消费者

收获园豆:3
通信的搞程序 | 小虾三级 |园豆:873 | 2019-09-10 22:33
其他回答(2)
0

消息中心配置了?

收获园豆:2
thelovelybugfly | 园豆:255 (菜鸟二级) | 2019-09-11 08:53
0

接收不到是正常的,消费者监听后信道立即关闭(看using代码),还没来得及等待消息推过来。

塞外骏马奔腾 | 园豆:204 (菜鸟二级) | 2019-10-08 16:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册