From 854e65c96b5eb85cd347366fae137fb0d37c5df2 Mon Sep 17 00:00:00 2001 From: zhangxiaofeng <1939543722@qq.com> Date: Thu, 9 May 2024 09:27:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E6=94=B6=E5=85=AC=E5=8F=B8=E3=80=81?= =?UTF-8?q?=E5=91=98=E5=B7=A5=E5=8F=98=E5=8A=A8=E6=B6=88=E6=81=AF=E6=8E=A8?= =?UTF-8?q?=E9=80=81bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MQ/RecCompanyUserChangeService.cs | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/Myshipping.Core/MQ/RecCompanyUserChangeService.cs b/Myshipping.Core/MQ/RecCompanyUserChangeService.cs index d95e4826..28009b88 100644 --- a/Myshipping.Core/MQ/RecCompanyUserChangeService.cs +++ b/Myshipping.Core/MQ/RecCompanyUserChangeService.cs @@ -58,21 +58,26 @@ namespace Myshipping.Core.MQ ConnectionFactory factory = new ConnectionFactory(); var repoSysCfg = _serviceScope.ServiceProvider.GetService>(); - var mqUrl = repoSysCfg.FirstOrDefault(x => x.Code == "CompanyUserChangeMqUrl").Value; - _logger.LogInformation($"准备连接公司用户同步消息队列:{mqUrl}"); - factory.Uri = new Uri(mqUrl); - mqConn = factory.CreateConnection("客户订舱平台客户端"); - - model = mqConn.CreateModel(); - model.ExchangeDeclare(ExchangeName, ExchangeType.Fanout); - model.QueueDeclare(QueueName, false, false, true, null); - model.QueueBind(QueueName, ExchangeName, "", null); - - var consumer = new EventingBasicConsumer(model); - consumer.Received += Consumer_Received; - model.BasicConsume(QueueName, true, consumer); - - + var mqUrl = repoSysCfg.FirstOrDefault(x => x.Code == "CompanyUserChangeMqUrl")?.Value; + if (string.IsNullOrEmpty(mqUrl)) + { + _logger.LogError($"接收公司、员工变动消息推送所需MQUrl未配置"); + } + else + { + _logger.LogInformation($"准备连接公司用户同步消息队列:{mqUrl}"); + factory.Uri = new Uri(mqUrl); + mqConn = factory.CreateConnection("客户订舱平台客户端"); + + model = mqConn.CreateModel(); + model.ExchangeDeclare(ExchangeName, ExchangeType.Fanout); + model.QueueDeclare(QueueName, false, false, true, null); + model.QueueBind(QueueName, ExchangeName, "", null); + + var consumer = new EventingBasicConsumer(model); + consumer.Received += Consumer_Received; + model.BasicConsume(QueueName, true, consumer); + } }); }