Ejemplo n.º 1
0
        public static async Task <bool> DeregisterService(string consulAgentUrl, string serviceId)
        {
            bool         statusCode;
            ConsulClient consulClient = new ConsulClient((ConsulClientConfiguration config) => config.Address = new Uri(consulAgentUrl));

            try
            {
                IAgentEndpoint    agent             = consulClient.Agent;
                string            str               = serviceId;
                CancellationToken cancellationToken = new CancellationToken();
                ConfiguredTaskAwaitable <WriteResult> configuredTaskAwaitable = agent.ServiceDeregister(str, cancellationToken).ConfigureAwait(false);
                statusCode = await configuredTaskAwaitable.StatusCode == HttpStatusCode.OK;
            }
            finally
            {
                if (consulClient != null)
                {
                    ((IDisposable)consulClient).Dispose();
                }
            }
            return(statusCode);
        }
Ejemplo n.º 2
0
        public static async Task <bool> HeartBeat(string consulAgentUrl, string checkId)
        {
            bool         statusCode;
            ConsulClient consulClient = new ConsulClient((ConsulClientConfiguration config) => config.Address = new Uri(consulAgentUrl));

            try
            {
                IAgentEndpoint    agent             = consulClient.Agent;
                string            str               = checkId;
                TTLStatus         pass              = TTLStatus.Pass;
                CancellationToken cancellationToken = new CancellationToken();
                ConfiguredTaskAwaitable <WriteResult> configuredTaskAwaitable = agent.UpdateTTL(str, null, pass, cancellationToken).ConfigureAwait(false);
                statusCode = await configuredTaskAwaitable.StatusCode == HttpStatusCode.OK;
            }
            finally
            {
                if (consulClient != null)
                {
                    ((IDisposable)consulClient).Dispose();
                }
            }
            return(statusCode);
        }
Ejemplo n.º 3
0
        public static async Task <bool> RegsterService(string consulAgentUrl, string name, string tags, string address, int port, int inerval, string httpcheck, string tcpCheck)
        {
            bool         statusCode;
            TimeSpan?    nullable;
            string       str;
            string       str1;
            TimeSpan?    nullable1;
            TimeSpan?    nullable2;
            ConsulClient consulClient = new ConsulClient((ConsulClientConfiguration config) => config.Address = new Uri(consulAgentUrl));

            try
            {
                IAgentEndpoint           agent = consulClient.Agent;
                AgentServiceRegistration agentServiceRegistration = new AgentServiceRegistration()
                {
                    Address = address,
                    ID      = name,
                    Name    = name,
                    Port    = port
                };
                AgentServiceRegistration agentServiceRegistration1 = agentServiceRegistration;
                string str2     = tags;
                char[] chrArray = new char[] { ',' };
                agentServiceRegistration1.Tags = str2.Split(chrArray);
                AgentServiceRegistration agentServiceRegistration2 = agentServiceRegistration;
                AgentServiceCheck        agentServiceCheck         = new AgentServiceCheck();
                AgentServiceCheck        agentServiceCheck1        = agentServiceCheck;
                if (!string.IsNullOrEmpty(httpcheck))
                {
                    str = httpcheck;
                }
                else
                {
                    str = null;
                }
                agentServiceCheck1.HTTP = str;
                AgentServiceCheck agentServiceCheck2 = agentServiceCheck;
                if (!string.IsNullOrEmpty(tcpCheck))
                {
                    str1 = tcpCheck;
                }
                else
                {
                    str1 = null;
                }
                agentServiceCheck2.TCP = str1;
                AgentServiceCheck agentServiceCheck3 = agentServiceCheck;
                if (!string.IsNullOrEmpty(httpcheck) || !string.IsNullOrEmpty(tcpCheck))
                {
                    nullable1 = new TimeSpan?(TimeSpan.FromSeconds((double)inerval));
                }
                else
                {
                    nullable  = null;
                    nullable1 = nullable;
                }
                agentServiceCheck3.Interval = nullable1;
                AgentServiceCheck agentServiceCheck4 = agentServiceCheck;
                if (!string.IsNullOrEmpty(httpcheck) || !string.IsNullOrEmpty(tcpCheck))
                {
                    nullable  = null;
                    nullable2 = nullable;
                }
                else
                {
                    nullable2 = new TimeSpan?(TimeSpan.FromSeconds((double)(2 * inerval)));
                }
                agentServiceCheck4.TTL          = nullable2;
                agentServiceCheck.Status        = CheckStatus.Passing;
                agentServiceRegistration2.Check = agentServiceCheck;
                AgentServiceRegistration agentServiceRegistration3            = agentServiceRegistration;
                CancellationToken        cancellationToken                    = new CancellationToken();
                ConfiguredTaskAwaitable <WriteResult> configuredTaskAwaitable = agent.ServiceRegister(agentServiceRegistration3, cancellationToken).ConfigureAwait(false);
                statusCode = await configuredTaskAwaitable.StatusCode == HttpStatusCode.OK;
            }
            finally
            {
                if (consulClient != null)
                {
                    ((IDisposable)consulClient).Dispose();
                }
            }
            return(statusCode);
        }