/// <summary>
 /// Initializes a new instance of the <see cref="ServiceDiscoveryHttpClientHandler"/> class.
 /// </summary>
 public ServiceDiscoveryHttpClientHandler(FeignClientHttpProxy feignClient, IServiceDiscovery serviceDiscovery, IServiceCacheProvider serviceCacheProvider, ILogger logger) : base(feignClient, logger)
 {
     _serviceResolve       = new RandomServiceResolve(logger);
     _serviceDiscovery     = serviceDiscovery;
     _serviceCacheProvider = serviceCacheProvider;
     ShouldResolveService  = true;
 }
        public async Task <IActionResult> GetServiceCache([FromServices] IServiceCacheProvider serviceCacheProvider, string queryParam)
        {
            var list = await serviceCacheProvider.GetServiceDescriptorAsync();

            var result = ServiceResult <IEnumerable <CacheDescriptor> > .Create(true, list);

            return(Json(result));
        }
        public async Task <IActionResult> GetCacheEndpoint([FromServices] IServiceCacheProvider serviceCacheProvider,
                                                           string cacheId)
        {
            var list = await serviceCacheProvider.GetCacheEndpointAsync(cacheId);

            var result = ServiceResult <IEnumerable <CacheEndpoint> > .Create(true, list);

            return(Json(result));
        }
Beispiel #4
0
        public FeignClientHttpProxy(IFeignOptions feignOptions, IServiceDiscovery serviceDiscovery, IServiceCacheProvider serviceCacheProvider, ILoggerFactory loggerFactory)
        {
            _feignOptions = feignOptions;
            //_logger = loggerFactory?.CreateLogger(this.GetType());
            _logger = loggerFactory?.CreateLogger(typeof(FeignClientHttpProxy));
            _globalFeignClientPipeline    = _feignOptions?.FeignClientPipeline as GlobalFeignClientPipeline;
            _serviceIdFeignClientPipeline = _globalFeignClientPipeline?.GetServicePipeline(ServiceId);
            ServiceDiscoveryHttpClientHandler serviceDiscoveryHttpClientHandler = new ServiceDiscoveryHttpClientHandler(this, serviceDiscovery, serviceCacheProvider, _logger);

            serviceDiscoveryHttpClientHandler.ShouldResolveService = string.IsNullOrWhiteSpace(Url);
            serviceDiscoveryHttpClientHandler.AllowAutoRedirect    = false;
            HttpClient = new HttpClient(serviceDiscoveryHttpClientHandler);
            string baseUrl = serviceDiscoveryHttpClientHandler.ShouldResolveService ? ServiceId ?? "" : Url;

            if (!baseUrl.StartsWith("http"))
            {
                baseUrl = $"http://{baseUrl}";
            }
            if (!string.IsNullOrWhiteSpace(BaseUri))
            {
                if (baseUrl.EndsWith("/"))
                {
                    baseUrl = baseUrl.TrimEnd('/');
                }
                if (BaseUri.StartsWith("/"))
                {
                    baseUrl += BaseUri;
                }
                else
                {
                    baseUrl += "/" + BaseUri;
                }
            }

            if (baseUrl.EndsWith("/"))
            {
                baseUrl = baseUrl.TrimEnd('/');
            }
            BaseUrl = baseUrl;

            InitializingEventArgs initializingEventArgs = new InitializingEventArgs(this);

            initializingEventArgs.HttpClient = HttpClient;
            OnInitializing(initializingEventArgs);
            HttpClient = initializingEventArgs.HttpClient;
            if (HttpClient == null)
            {
                throw new ArgumentNullException(nameof(HttpClient));
            }
        }
        public static IList <IServiceInstance> GetServiceInstancesWithCache(this IServiceDiscovery serviceDiscovery, string serviceId, IServiceCacheProvider serviceCacheProvider, string serviceInstancesKeyPrefix = "ServiceDiscovery-ServiceInstances-")
        {
            // if distributed cache was provided, just make the call back to the provider
            if (serviceCacheProvider != null)
            {
                // check the cache for existing service instances
                var services = serviceCacheProvider.Get(serviceInstancesKeyPrefix + serviceId);
                if (services != null && services.Count > 0)
                {
                    return(services);
                }
            }

            // cache not found or instances not found, call out to the provider
            var instances = serviceDiscovery.GetServiceInstances(serviceId) ?? new List <IServiceInstance>();

            if (serviceCacheProvider != null)
            {
                serviceCacheProvider.Set(serviceInstancesKeyPrefix + serviceId, instances, TimeSpan.FromMinutes(10));
            }

            return(instances);
        }
        public async Task <IActionResult> EditCacheEndPoint([FromServices] IServiceCacheProvider serviceCacheProvider, CacheEndpointParam param)
        {
            await serviceCacheProvider.SetCacheEndpointByEndpoint(param.CacheId, param.Endpoint, param.CacheEndpoint);

            return(Json(ServiceResult.Create(true)));
        }
        public async Task <IActionResult> DelCacheEndPoint([FromServices] IServiceCacheProvider serviceCacheProvider, string cacheId, string endpoint)
        {
            await serviceCacheProvider.DelCacheEndpointAsync(cacheId, endpoint);

            return(Json(ServiceResult.Create(true)));
        }
        public async Task <IActionResult> EditCacheEndPoint([FromServices] IServiceCacheProvider serviceCacheProvider, string cacheId, string endpoint)
        {
            var model = await serviceCacheProvider.GetCacheEndpointAsync(cacheId, endpoint);

            return(View(model));
        }
Beispiel #9
0
 public FallbackFeignClientHttpProxy(IFeignOptions feignOptions, IServiceDiscovery serviceDiscovery, IServiceCacheProvider serviceCacheProvider, ILoggerFactory loggerFactory, object fallback) : base(feignOptions, serviceDiscovery, serviceCacheProvider, loggerFactory)
 {
     _fallback = fallback;
 }
Beispiel #10
0
 public FallbackFactoryFeignClientHttpProxy(IFeignOptions feignOptions, IServiceDiscovery serviceDiscovery, IServiceCacheProvider serviceCacheProvider, ILoggerFactory loggerFactory, TFallbackFactory fallbackFactory) : base(feignOptions, serviceDiscovery, serviceCacheProvider, loggerFactory, GetFallback(fallbackFactory))
 {
     FallbackFactory = fallbackFactory;
 }
 public FallbackFeignClientHttpProxy(IFeignOptions feignOptions, IServiceDiscovery serviceDiscovery, IServiceCacheProvider serviceCacheProvider, ILoggerFactory loggerFactory, TFallback fallback) : base(feignOptions, serviceDiscovery, serviceCacheProvider, loggerFactory, fallback)
 {
     Fallback = fallback;
     _serviceTypeFeignClientPipeline = _globalFeignClientPipeline?.GetServicePipeline <TService>();
 }
 public TestFeignClientHttpProxy(IFeignOptions feignOptions, IServiceDiscovery serviceDiscovery, IServiceCacheProvider serviceCacheProvider, Feign.Logging.ILoggerFactory loggerFactory) : base(feignOptions, serviceDiscovery, serviceCacheProvider, loggerFactory)
 {
 }