Beispiel #1
0
 /// <summary>
 /// Enables service discovery using consul to resolve the correct url for a remote RequestDTO
 /// </summary>
 public ConsulFeature(ConsulSettings settings = null)
 {
     Settings = new ConsulFeatureSettings();
     if (settings != null)
     {
         settings.Invoke(Settings);
     }
 }
        private ServiceHealthCheck CreateCustomCheck(string baseUrl, string serviceId, ConsulFeatureSettings settings)
        {
            var customHealthCheck = settings.GetHealthCheck();

            if (customHealthCheck == null)
            {
                return(null);
            }

            return(new ServiceHealthCheck
            {
                Id = "SS-HealthCheck",
                ServiceId = serviceId,
                IntervalInSeconds = customHealthCheck.IntervalInSeconds,
                DeregisterCriticalServiceAfterInMinutes = customHealthCheck.DeregisterIfCriticalAfterInMinutes,
                Http = baseUrl.CombineWith("/json/reply/healthcheck"),
                Notes = "This check is an HTTP GET request which expects the service to return 200 OK"
            });
        }
        private ServiceHealthCheck[] CreateHealthChecks(ServiceRegistration registration, ConsulFeatureSettings settings)
        {
            var checks    = new List <ServiceHealthCheck>();
            var serviceId = registration.Id;
            var baseUrl   = registration.Address;

            if (settings.IncludeDefaultServiceHealth)
            {
                //注册心跳
                var heartbeatCheck = CreateHeartbeatCheck(baseUrl + registration.Port, serviceId);
                checks.Add(heartbeatCheck);

                //var redisCheck = CreateRedisCheck(serviceId);
                //if (redisCheck != null)
                //    checks.Add(redisCheck);
            }

            //注册healthCheck
            //var customCheck = CreateCustomCheck(baseUrl, serviceId, settings);
            //if (customCheck != null)
            //    checks.Add(customCheck);

            // TODO Setup health checks for any registered IDbConnectionFactories

            return(checks.ToArray());
        }