chore: 消除构建警告并升级依赖

This commit is contained in:
2025-12-02 11:18:38 +08:00
parent e8777faf71
commit 3e01943727
4 changed files with 20 additions and 13 deletions

View File

@@ -25,14 +25,15 @@ public sealed class RabbitMqMessagePublisher(RabbitMqConnectionFactory connectio
EnsureChannel();
var options = optionsMonitor.CurrentValue;
_channel!.ExchangeDeclare(options.Exchange, options.ExchangeType, durable: true, autoDelete: false);
var channel = _channel ?? throw new InvalidOperationException("RabbitMQ channel is not available.");
channel.ExchangeDeclare(options.Exchange, options.ExchangeType, durable: true, autoDelete: false);
var body = serializer.Serialize(message);
var props = _channel.CreateBasicProperties();
var props = channel.CreateBasicProperties();
props.ContentType = "application/json";
props.DeliveryMode = 2;
props.MessageId = Guid.NewGuid().ToString("N");
_channel.BasicPublish(options.Exchange, routingKey, props, body);
channel.BasicPublish(options.Exchange, routingKey, props, body);
logger.LogDebug("发布消息到交换机 {Exchange} RoutingKey {RoutingKey}", options.Exchange, routingKey);
return Task.CompletedTask;
}