c# - 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);
};
解决方案
推荐阅读
- vue.js - 获取子组件中未定义的道具值
- asp.net - Web API 作为 Windows 服务
- int - ArrayIndexOutOfBoundsException Appears and highlights " pixels[loc] = c; "
- javascript - 如何在我的登录屏幕后设置导航反应本机
- material-table - material table onRowClick and actions button click overlapping
- node.js - Node/Express Route 'Show' presenting too many results
- python - Pandas Group By 和 Sum ,标题被删除
- jsf - Adding leading zeroes to an inputMask
- python - Python JSON 到 MYSQL - 动态
- java - 出现错误“ [junit] java.lang.OutOfMemoryError: PermGen space