From 4dacae22631ee2c6e62535873f9adc679c290a13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Tue, 23 Nov 2021 03:09:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0CAP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Yi.Framework.ApiMicroservice/Startup.cs | 5 ++ .../MiddlewareExtend/CAPExtend.cs | 59 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/CAPExtend.cs diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Startup.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Startup.cs index 86a2bf8f..e7bab1a9 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Startup.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Startup.cs @@ -79,6 +79,11 @@ namespace Yi.Framework.ApiMicroservice //短信服务配置 #endregion services.AddSMSService(); + + #region + //CAP服务配置 + #endregion + services.AddCAPService(); } #region Autofac容器注入 diff --git a/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/CAPExtend.cs b/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/CAPExtend.cs new file mode 100644 index 00000000..b7014130 --- /dev/null +++ b/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/CAPExtend.cs @@ -0,0 +1,59 @@ +锘縰sing DotNetCore.CAP.Dashboard.NodeDiscovery; +using DotNetCore.CAP.Messages; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.WebCore.MiddlewareExtend +{ + public static class CAPExtend + { + public static IServiceCollection AddCAPService(this IServiceCollection services) + { + if (Appsettings.appBool("CAP_Enabled")) + { + services.AddCap(x => + { + x.UseMySql(Appsettings.app("DbConn", "WriteUrl")); + + x.UseRabbitMQ(optios => { + optios.HostName = Appsettings.app("RabbitConn", "HostName"); + optios.Port =Convert.ToInt32(Appsettings.app("RabbitConn", "Port")); + optios.UserName = Appsettings.app("RabbitConn", "UserName"); + optios.Password = Appsettings.app("RabbitConn", "Password"); + + }); + x.FailedRetryCount = 30; + x.FailedRetryInterval = 60;//second + x.FailedThresholdCallback = failed => + { + var logger = failed.ServiceProvider.GetService>(); + logger.LogError($@"MessageType {failed.MessageType} 澶辫触浜嗭紝 閲嶈瘯浜 {x.FailedRetryCount} 娆, + 娑堟伅鍚嶇О: {failed.Message.GetName()}");//do anything + }; + if (Appsettings.appBool("CAPDashboard_Enabled")) + { + x.UseDashboard(); + var discoveryOptions = Appsettings.app(); + x.UseDiscovery(d => + { + d.DiscoveryServerHostName = discoveryOptions.DiscoveryServerHostName; + d.DiscoveryServerPort = discoveryOptions.DiscoveryServerPort; + d.CurrentNodeHostName = discoveryOptions.CurrentNodeHostName; + d.CurrentNodePort = discoveryOptions.CurrentNodePort; + d.NodeId = discoveryOptions.NodeId; + d.NodeName = discoveryOptions.NodeName; + d.MatchPath = discoveryOptions.MatchPath; + }); + } + }); + + } + return services; + } + } +}