Azure功能RabbitMQ触发器停止接收消息
我具有带有RabbitMQ触发器的Azure功能,并且在特定时间后停止接收任何消息。该功能部署在Azure中。当我停下来然后重新启动功能时,它会再次开始拉消息,但是过了一会儿就停止了。当我在机器上本地运行它时,问题永远不会发生。我的代码看起来像这样:
[FunctionName(nameof(Bets))]
public async Task Bets([RabbitMQTrigger(nameof(Bets), ConnectionStringSetting = "RabbitConnection")] BasicDeliverEventArgs args,
[RabbitMQ(ConnectionStringSetting = "RabbitConnection")] IModel client, ILogger log)
{
var myQueueItem = Encoding.UTF8.GetString(args.Body);
var logEntry = new Log()
{
date = DateTime.UtcNow,
status = SuccessStatus,
input = myQueueItem,
queue = nameof(Bets)
};
try
{
var input = JsonConvert.DeserializeObject<Bet[]>(myQueueItem);
await _context.BulkInsertOrUpdateAsync(input);
log.LogInformation($"Finished input save: {myQueueItem}");
}
catch (Exception e)
{
client.BasicNack(args.DeliveryTag, false, true);
logEntry.status = "Error";
logEntry.error = e.Message;
log.LogError(e, e.Message, myQueueItem);
}
await _context.logs.AddAsync(logEntry);
await _context.SaveChangesAsync();
}
I have Azure Function with RabbitMq trigger and it stops receiving any messages after certain time. The function is deployed in Azure. When I stop and then start again the function, it starts pulling messages again, but after a while it stops. When I run it locally on my machine the problem never occurs. My code looks like this:
[FunctionName(nameof(Bets))]
public async Task Bets([RabbitMQTrigger(nameof(Bets), ConnectionStringSetting = "RabbitConnection")] BasicDeliverEventArgs args,
[RabbitMQ(ConnectionStringSetting = "RabbitConnection")] IModel client, ILogger log)
{
var myQueueItem = Encoding.UTF8.GetString(args.Body);
var logEntry = new Log()
{
date = DateTime.UtcNow,
status = SuccessStatus,
input = myQueueItem,
queue = nameof(Bets)
};
try
{
var input = JsonConvert.DeserializeObject<Bet[]>(myQueueItem);
await _context.BulkInsertOrUpdateAsync(input);
log.LogInformation(quot;Finished input save: {myQueueItem}");
}
catch (Exception e)
{
client.BasicNack(args.DeliveryTag, false, true);
logEntry.status = "Error";
logEntry.error = e.Message;
log.LogError(e, e.Message, myQueueItem);
}
await _context.logs.AddAsync(logEntry);
await _context.SaveChangesAsync();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试在函数应用程序配置中配置常规设置选项卡下的选项“始终在”上,这会阻止您的应用程序由于不活动而被闲置。
You could try to configure within your function app configuration under general settings tab the option "always on" which Prevents your app from being idled out due to inactivity.