Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        public async Task FindByTags_ShouldReturnNullWhenTagsAreNull()
        {
            var result = await _serviceRegistry.FindByTags(null);

            result.Count.Should().Be(0);
        }