コード例 #1
0
ファイル: ServiceLocator.cs プロジェクト: samjwest/Heimdall
        /// <summary>
        /// Find the existance of a service that is available to process the given route.
        /// Optionally, accept a qualifying domain used to segregate underlying services into specialized domains.
        /// </summary>
        /// <param name="domain"></param>
        /// <param name="route"></param>
        /// <returns></returns>
        public async Task <IGatewayService> Find(string domain, string route)
        {
            if (string.IsNullOrEmpty(route))
            {
                return(null);
            }

            _logger.LogInformation($"Request for route [{route}] with domain = {domain} received.");

            //TODO: Deal with domains later
            if (route.StartsWith('/'))
            {
                route = route.Substring(1);
            }

            var tokens = ExtractTokens(route);

            try
            {
                // Plug in Registry and lookup route - should return a list of endpoints registered for the given token list
                var endpoints = await _serviceRegistry.FindByTags(tokens);

                if (endpoints == null || endpoints.Count == 0)
                {
                    return(null);
                }

                var svcLogger = _loggerFactory.CreateLogger <IGatewayService>();
                var service   = new GatewayService(_clientFactory)
                                .WithEndpoints(endpoints)
                                .WithRoute(route)
                                .Configure(svcLogger);

                _logger.LogInformation($"{endpoints.Count} Services matching route found");
                return(service);
            }
            catch (Exception ex)
            {
                string errMsg = $"Error occured while finding {route}";
                _logger.LogError(errMsg, ex);

                if (ex is RegistryUnavailableException)
                {
                    errMsg = "Service Registry is not responding";
                    _logger.LogError(errMsg);
                }
            }

            return(null);
        }
コード例 #2
0
 public static GatewayService WithRoute(this GatewayService service, string route)
 {
     service.IdentifiedRoute = route;
     return(service);
 }
コード例 #3
0
 public static GatewayService WithEndpoints(this GatewayService service, List <ServiceEndpoint> serviceEndpoints)
 {
     service.DiscoveredEndpoints = serviceEndpoints;
     return(service);
 }
コード例 #4
0
 public static GatewayService AddEndpoint(this GatewayService service, ServiceEndpoint serviceEndpoint)
 {
     //service.Uri = serviceEndpoint.ServiceUri;
     service.IdentifiedRoute = serviceEndpoint.Route.Url;
     return(service);
 }