From 8946ca33af4ed7ec61c4313130a00f787d163da4 Mon Sep 17 00:00:00 2001 From: zhangq <943620963@qq.com> Date: Tue, 17 Nov 2020 09:30:56 +0800 Subject: [PATCH] support consul service check for https (#722) --- .../NodeDiscovery/CAP.DiscoveryOptions.cs | 6 +++++ .../INodeDiscoveryProvider.Consul.cs | 23 +++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/DotNetCore.CAP.Dashboard/NodeDiscovery/CAP.DiscoveryOptions.cs b/src/DotNetCore.CAP.Dashboard/NodeDiscovery/CAP.DiscoveryOptions.cs index 6b720eb..8d2e3b6 100644 --- a/src/DotNetCore.CAP.Dashboard/NodeDiscovery/CAP.DiscoveryOptions.cs +++ b/src/DotNetCore.CAP.Dashboard/NodeDiscovery/CAP.DiscoveryOptions.cs @@ -13,6 +13,8 @@ namespace DotNetCore.CAP.Dashboard.NodeDiscovery public const string DefaultMatchPath = "/cap"; + public const string DefaultScheme = "http"; + public DiscoveryOptions() { DiscoveryServerHostName = DefaultDiscoveryServerHost; @@ -22,6 +24,8 @@ namespace DotNetCore.CAP.Dashboard.NodeDiscovery CurrentNodePort = DefaultCurrentNodePort; MatchPath = DefaultMatchPath; + + Scheme = DefaultScheme; } public string DiscoveryServerHostName { get; set; } @@ -34,5 +38,7 @@ namespace DotNetCore.CAP.Dashboard.NodeDiscovery public string NodeName { get; set; } public string MatchPath { get; set; } + + public string Scheme { get; set; } } } \ No newline at end of file diff --git a/src/DotNetCore.CAP.Dashboard/NodeDiscovery/INodeDiscoveryProvider.Consul.cs b/src/DotNetCore.CAP.Dashboard/NodeDiscovery/INodeDiscoveryProvider.Consul.cs index 6947b2d..df8bd2b 100644 --- a/src/DotNetCore.CAP.Dashboard/NodeDiscovery/INodeDiscoveryProvider.Consul.cs +++ b/src/DotNetCore.CAP.Dashboard/NodeDiscovery/INodeDiscoveryProvider.Consul.cs @@ -69,21 +69,26 @@ namespace DotNetCore.CAP.Dashboard.NodeDiscovery { try { + var healthCheck = new AgentServiceCheck + { + DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(30), + Interval = TimeSpan.FromSeconds(10), + Status = HealthStatus.Passing + }; + + if (_options.Scheme.Equals("http", StringComparison.OrdinalIgnoreCase)) + healthCheck.HTTP = $"http://{_options.CurrentNodeHostName}:{_options.CurrentNodePort}{_options.MatchPath}/health"; + else if (_options.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)) + healthCheck.TCP = $"{_options.CurrentNodeHostName}:{_options.CurrentNodePort}"; + return _consul.Agent.ServiceRegister(new AgentServiceRegistration { ID = _options.NodeId, Name = _options.NodeName, Address = _options.CurrentNodeHostName, Port = _options.CurrentNodePort, - Tags = new[] {"CAP", "Client", "Dashboard"}, - Check = new AgentServiceCheck - { - DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(30), - Interval = TimeSpan.FromSeconds(10), - Status = HealthStatus.Passing, - HTTP = - $"http://{_options.CurrentNodeHostName}:{_options.CurrentNodePort}{_options.MatchPath}/health" - } + Tags = new[] { "CAP", "Client", "Dashboard" }, + Check = healthCheck }); } catch (Exception ex)