예제 #1
0
        private static async Task <IKeyValueStore> TryGetEtcdKeyValueStore()
        {
            foreach (var kvsAgent in KnownAgents.Get(WellKnownAgentType.KeyValueStore))
            {
                IKeyValueStore keyValueStore = await EtcdKeyValueStore.TryConnectAsync(kvsAgent);

                if (keyValueStore != null)
                {
                    return(keyValueStore);
                }
            }

            // Do not just try the default address - Etcd might be running with a different purpose

            return(null);
        }
예제 #2
0
        private async Task <ServiceRegistry> CreateServiceRegistryAsync()
        {
            Stopwatch watch = Stopwatch.StartNew();

            IKeyValueStore keyValueStore = await TryGetEtcdKeyValueStore();

            List <AgentConfiguration> serviceAgents = new List <AgentConfiguration>();

            if (keyValueStore != null)
            {
                _logger.LogInformation("Connected to distributed key-value store in {millis}ms",
                                       watch.ElapsedMilliseconds);
            }
            else
            {
                _logger.LogWarning(
                    "Unable to connect to distributed key-value store. Using Worker agents from configuration:");

                keyValueStore = new LocalKeyValueStore();

                _keyValueStoreIsLocal = true;

                serviceAgents.AddRange(KnownAgents.Get(WellKnownAgentType.Worker));
            }

            ServiceRegistry serviceRegistry = new ServiceRegistry(keyValueStore, string.Empty);

            AddServices(serviceRegistry, serviceAgents);

            int endpointCount = serviceRegistry.GetTotalEndpointCount(out var serviceCount);

            _logger.LogInformation(
                "Service registry contains {serviceCount} service type(s) at {endpointCount} " +
                "different endpoints.", serviceCount, endpointCount);

            return(serviceRegistry);
        }