Esempio n. 1
0
        public static IServiceCollection AddCondenser(this IServiceCollection self, string agentAddress, int agentPort,
                                                      IHealthConfig health, IRoutingConfig routingConfig, IHttpClientConfig httpClientConfig)
        {
            var config = new CondenserConfiguration
            {
                AgentPort    = agentPort,
                AgentAddress = agentAddress
            };

            self.AddSingleton(config);
            self.AddSingleton(health);
            self.AddSingleton(routingConfig);
            self.AddSingleton(httpClientConfig);

            self.AddSingleton <RoutingData>();
            self.AddSingleton <IService, HealthRouter>();
            self.AddSingleton <IService, RouteSummary>();
            self.AddSingleton <IService, TreeRouter>();
            self.AddSingleton <IService, ChangeRoutingStrategy>();
            self.AddSingleton <IService, ServerStatsRoute>();
            self.AddTransient <IRoutingStrategy <IService>, RandomRoutingStrategy <IService> >();
            self.AddTransient <IRoutingStrategy <IService>, RoundRobinRoutingStrategy <IService> >();
            self.AddSingleton <IDefaultRouting <IService>, DefaultRouting <IService> >();

            self.AddTransient <ChildContainer <IService> >();
            self.AddSingleton <CurrentState>();
            self.AddSingleton <CustomRouter>();
            self.AddSingleton <RoutingHost>();
            self.AddSingleton <RadixTree <IService> >();

            self.AddTransient <Service>();
            self.AddSingleton <Func <IConsulService> >(x => x.GetService <Service>);
            self.AddSingleton <Func <ChildContainer <IService> > >(x => x.GetService <ChildContainer <IService> >);
            return(self);
        }
Esempio n. 2
0
        private static IServiceCollection AddCondenser(this IServiceCollection self, string agentAddress, int agentPort)
        {
            var config = new CondenserConfiguration
            {
                AgentPort    = agentPort,
                AgentAddress = agentAddress
            };

            self.AddSingleton(config);
            self.AddTransient <Service>();
            self.AddSingleton <Func <IConsulService> >(x => x.GetService <Service>);
            self.AddSingleton <CurrentState>();
            self.AddTransient <IRoutingStrategy <IService>, RandomRoutingStrategy <IService> >();
            self.AddTransient <IRoutingStrategy <IService>, RoundRobinRoutingStrategy <IService> >();
            self.AddSingleton <IDefaultRouting <IService>, DefaultRouting <IService> >();
            self.AddSingleton <Func <string, HttpClient> >(s => new HttpClient());
            Func <ChildContainer <IService> > factory = () =>
            {
                var randomRoutingStrategy = new RandomRoutingStrategy <IService>();
                return(new ChildContainer <IService>(new DefaultRouting <IService>(new[] { randomRoutingStrategy }, null)));
            };

            self.AddSingleton(new RoutingData(new RadixTree <IService>(factory)));
            self.AddSingleton <CustomRouter>();
            self.AddSingleton <RoutingHost>();
            return(self);
        }
        public ConsulRouteSource(CondenserConfiguration config,
                                 ILoggerFactory logger, IConsulAclProvider aclProvider = null)
        {
            _client           = HttpUtils.CreateClient(aclProvider, config.AgentAddress, config.AgentPort);
            _healthCheckUri   = $"{HttpUtils.HealthAnyUrl}?index=";
            _serviceLookupUri = $"{HttpUtils.SingleServiceCatalogUrl}";

            _logger = logger?.CreateLogger <ConsulRouteSource>();
        }
        public ConsulRouteSource(CondenserConfiguration config,
                                 ILoggerFactory logger)
        {
            _client.Timeout = TimeSpan.FromMinutes(6);

            _healthCheckUri   = $"http://{config.AgentAddress}:{config.AgentPort}{HttpUtils.HealthAnyUrl}?index=";
            _serviceLookupUri = $"http://{config.AgentAddress}:{config.AgentPort}{HttpUtils.SingleServiceCatalogUrl}";

            _logger = logger?.CreateLogger <ConsulRouteSource>();
        }
Esempio n. 5
0
        public RoutingHost(CustomRouter router, CondenserConfiguration config, ILoggerFactory logger,
                           RoutingData routingData, IEnumerable <IService> customRoutes, Func <IConsulService> serviceFactory)
        {
            _routingData      = routingData;
            _serviceFactory   = serviceFactory;
            _logger           = logger?.CreateLogger <RoutingHost>();
            _client.Timeout   = TimeSpan.FromMinutes(6);
            _router           = router;
            _healthCheckUri   = $"http://{config.AgentAddress}:{config.AgentPort}{HttpUtils.HealthAnyUrl}?index=";
            _serviceLookupUri = $"http://{config.AgentAddress}:{config.AgentPort}{HttpUtils.SingleServiceCatalogUrl}";
            var ignore = WatchLoop();

            foreach (var customRoute in customRoutes)
            {
                _router.AddNewService(customRoute);
            }
        }