From c220524d1d95fc24c88d565c790de77ece2bd74a Mon Sep 17 00:00:00 2001 From: eithday Date: Tue, 26 Aug 2025 14:35:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3RabbitMQ=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E5=B0=B1=E8=8E=B7=E5=8F=96=E9=80=9A=E9=81=93?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Admin.NET/Admin.NET.Core/RabbitMQ/RabbitMqConsumer.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Admin.NET/Admin.NET.Core/RabbitMQ/RabbitMqConsumer.cs b/Admin.NET/Admin.NET.Core/RabbitMQ/RabbitMqConsumer.cs index ed48d9c6..6d796e36 100644 --- a/Admin.NET/Admin.NET.Core/RabbitMQ/RabbitMqConsumer.cs +++ b/Admin.NET/Admin.NET.Core/RabbitMQ/RabbitMqConsumer.cs @@ -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);