Пример #1
0
 protected ServiceRouteManagerBase(ServiceRouteCache serviceRouteCache,
                                   IServiceEntryManager serviceEntryManager,
                                   ILockerProvider lockerProvider,
                                   IOptions <RegistryCenterOptions> registryCenterOptions,
                                   IOptions <RpcOptions> rpcOptions)
 {
     _serviceRouteCache     = serviceRouteCache;
     _serviceEntryManager   = serviceEntryManager;
     _lockerProvider        = lockerProvider;
     _registryCenterOptions = registryCenterOptions.Value;
     _rpcOptions            = rpcOptions.Value;
     Check.NotNullOrEmpty(_registryCenterOptions.RoutePath, nameof(_registryCenterOptions.RoutePath));
     Check.NotNullOrEmpty(_rpcOptions.Token, nameof(_rpcOptions.Token));
     _serviceRouteCache.OnRemoveServiceRoutes += async descriptors =>
     {
         if (_rpcOptions.RemoveUnhealthServer)
         {
             foreach (var descriptor in descriptors)
             {
                 await RegisterRouteWithLockAsync(descriptor);
             }
         }
     };
 }
        public DefaultZookeeperClientProvider(IOptions <RegistryCenterOptions> registryCenterOptions)
        {
            _registryCenterOptions = registryCenterOptions.Value;
            Check.NotNullOrEmpty(_registryCenterOptions.ConnectionStrings,
                                 nameof(_registryCenterOptions.ConnectionStrings));
            Logger = NullLogger <DefaultZookeeperClientProvider> .Instance;
            CreateZookeeperClients();
            _timer           = new Timer(TimeSpan.FromSeconds(_registryCenterOptions.HealthCheckInterval).TotalMilliseconds);
            _timer.Enabled   = true;
            _timer.AutoReset = true;
            _timer.Elapsed  += (sender, args) =>
            {
                foreach (var client in _zookeeperClients)
                {
                    if (!client.Value.WaitUntilConnected(TimeSpan.FromSeconds(_registryCenterOptions.ConnectionTimeout)))

                    {
                        _zookeeperClients.TryRemove(client.Key, out IZookeeperClient removeClient);
                        removeClient?.Dispose();
                    }
                }
                CreateZookeeperClients();
            };
        }