Merge pull request 'v2' (#422) from eithday/Admin.NET.Pro:v2 into v2

Reviewed-on: https://code.adminnet.top/Admin.NET/Admin.NET.Pro/pulls/422
This commit is contained in:
zuohuaijun 2025-08-26 15:12:55 +08:00
commit 0ecf99ba1a

View File

@ -21,15 +21,16 @@ public class RabbitMqConsumer : BackgroundService
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
var channel = _connection.Channel;
if (channel == null)
throw new InvalidOperationException("RabbitMQ channel is null");
if (!await _connection.TryConnectAsync())
{
_logger.LogError($"RabbitMQ连接失败请检查配置文件。");
return;
}
var channel = _connection.Channel;
if (channel == null)
throw new InvalidOperationException("RabbitMQ channel is null");
await channel.QueueDeclareAsync(queue: _handler.QueueName, durable: true, exclusive: false, autoDelete: false, arguments: null);
await channel.BasicQosAsync(prefetchSize: 0, prefetchCount: 1, global: false);
var consumer = new AsyncEventingBasicConsumer(channel);