首页 > 解决方案 > RabbitMQ EventingBasicConsumer 一段时间后没有响应

问题描述

我在我的 .NET Core 应用程序中使用 RabbitClient 作为队列阅读器单例(发布到队列通过其他应用程序)。一段时间后我的应用程序停止从队列中读取时,我遇到了这个问题。我在 AKS 上托管了我的服务。下面是我的代码。它可以正常运行 2 到 5 分钟并处理消息,但之后它会停止并且不读取消息。当我停止接收消息时,我的消费者保持连接到 RabbitMQ 服务器。我的 RabbitMQ 服务器版本是 3.8.4

enter code here
 consumer.Received += (model, ea) =>
                {
                    var watch = System.Diagnostics.Stopwatch.StartNew();
                    var body = ea.Body;
                    var message = Encoding.UTF8.GetString(body);
                    log.InfoFormat("[ {0} ] New Message received", customerid);

                    log.Warn("to troubleshoot deployemnt issue");

                    string assetid = null;

                    try
                    {


                            List<AlarmLog> lia = ds.calculateAlarm(assetid, assettype, customerid, timest);
                            log.Debug($"Total alarms generated for {assetid} is {lia.Count}");


                            if (lia.Count > 0)
                            {
                                channel.BasicPublish(exchange: Aura.Config.Config.Instance.NotificationExchange,
                                        routingKey: "",
                                        basicProperties: null,
                                        body: Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(lia)));
                            }


                        channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);

                    }
                    catch(Exception overall)
                    {
                        log.Error($"error in consumer.Received: assetid: {assetid}. " + overall.ToString());
                        channel.BasicReject(deliveryTag: ea.DeliveryTag, requeue: false);
                    }

                    watch.Stop();
                    Thread.Sleep(500);
                    log.Debug("[ " + customerid + " ]" + "Completed " + ea.DeliveryTag + " of activities in " + watch.ElapsedMilliseconds);
                };

标签: c#rabbitmq

解决方案


推荐阅读