Exemplo n.º 1
0
        public async Task StopAsync()
        {
            _logger.LogInformation("Unregistering from Nacos");

            var removeRequest = new RemoveInstanceRequest
            {
                ServiceName = _options.ServiceName,
                Ip          = uri.Host,
                Port        = uri.Port,
                GroupName   = _options.GroupName,
                NamespaceId = _options.Namespace,
                ClusterName = _options.ClusterName,
                Ephemeral   = false
            };

            for (int i = 0; i < 3; i++)
            {
                try
                {
                    var flag = await _client.RemoveInstanceAsync(removeRequest);

                    _logger.LogDebug("remove instance, status = {0}", flag);
                    break;
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Unregistering error, count = {0}", i + 1);
                }
            }

            _timer?.Change(Timeout.Infinite, 0);
            _timer?.Dispose();
        }
        public async Task StopAsync(CancellationToken cancellationToken)
        {
            _logger.LogWarning("Unregistering from Nacos, serviceName={0}", _options.ServiceName);

            var removeRequest = new RemoveInstanceRequest
            {
                ServiceName = _options.ServiceName,
                Ip          = uri.Host,
                Port        = uri.Port,
                GroupName   = _options.GroupName,
                NamespaceId = _options.Namespace,
                ClusterName = _options.ClusterName,
                Ephemeral   = true
            };

            for (int i = 0; i < 3; i++)
            {
                try
                {
                    _logger.LogWarning("begin to remove instance, {0}", JsonConvert.SerializeObject(removeRequest));
                    var flag = await _client.RemoveInstanceAsync(removeRequest);

                    _logger.LogWarning("remove instance, status = {0}", flag);
                    break;
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Unregistering error, count = {0}", i + 1);
                }
            }

            _timer?.Change(Timeout.Infinite, 0);
        }
Exemplo n.º 3
0
        public void Deregister(INacosRegistration registration)
        {
            RemoveInstanceRequest request = new RemoveInstanceRequest()
            {
                Ip          = registration.Host,
                Port        = registration.Port,
                ServiceName = registration.ServiceId
            };

            _nacosClient.RemoveInstanceAsync(request);
        }
Exemplo n.º 4
0
        public Task ShutdownAsync()
        {
            var tempRegistration = _registrar.Registration;
            var removeRequest    = new RemoveInstanceRequest
            {
                ServiceName = tempRegistration.ServiceId,
                Ip          = tempRegistration.Host,
                Port        = tempRegistration.Port,
                GroupName   = tempRegistration.GroupName,
                NamespaceId = tempRegistration.Namespace,
                ClusterName = tempRegistration.ClusterName,
                Ephemeral   = tempRegistration.Ephemeral
            };

            return(_client.RemoveInstanceAsync(removeRequest));
        }