internal FallbackRequestEventArgs(IFeignClient <TService> feignClient, FeignClientHttpRequest request, TService fallback, IFallbackProxy fallbackProxy, MethodInfo method) : base(feignClient)
 {
     Request       = request;
     Fallback      = fallback;
     FallbackProxy = fallbackProxy;
     _method       = method;
 }
        static string GetMessage(IFeignClient feignClient, FeignHttpRequestMessage httpRequestMessage, Exception exception)
        {
            //string url = BuildUrl(httpRequestMessage.FeignClientRequest.BaseUrl, httpRequestMessage.FeignClientRequest.MappingUri);
            string url = httpRequestMessage.RequestUri.ToString();

            return($"{httpRequestMessage.Method.Method} request error on {url} : {exception.Message}");
        }
 public FallbackRequestEventArgs(IFeignClient feignClient, FeignClientRequest request, object fallback, IFallbackProxy fallbackProxy, MethodInfo method) : base(feignClient)
 {
     Request       = request;
     Fallback      = fallback;
     FallbackProxy = fallbackProxy;
     _method       = method;
 }
示例#4
0
 internal IAsyncPolicy SetupGlobalPolly(IAsyncPolicy asyncPolicy, IFeignClient <object> feignClient)
 {
     //global
     _globalPolicySetups.ForEach(setup => asyncPolicy      = setup.Invoke(asyncPolicy));
     _globalPolicyAsyncSetups.ForEach(setup => asyncPolicy = setup.Invoke(asyncPolicy).ConfigureAwait(false).GetAwaiter().GetResult());
     return(asyncPolicy);
 }
 internal BuildingRequestEventArgs(IFeignClient <TService> feignClient, string method, Uri requestUri, IDictionary <string, string> headers, FeignClientHttpRequest request) : base(feignClient)
 {
     Method     = method;
     RequestUri = requestUri;
     Headers    = headers;
     Request    = request;
 }
 internal ErrorRequestEventArgs(IFeignClient <TService> feignClient, Exception exception) : base(feignClient)
 {
     Exception = exception;
     if (exception is FeignHttpRequestException)
     {
         RequestMessage = ((FeignHttpRequestException)exception).RequestMessage;
     }
 }
示例#7
0
        internal IAsyncPolicy SetupAllPolly(IFeignClient <object> feignClient)
        {
            IAsyncPolicy asyncPolicy = Policy.NoOpAsync();

            asyncPolicy = SetupServiceTypePolly(asyncPolicy, feignClient);
            asyncPolicy = SetupServiceIdPolly(asyncPolicy, feignClient);
            asyncPolicy = SetupGlobalPolly(asyncPolicy, feignClient);
            return(asyncPolicy);
        }
示例#8
0
        public static TService GetFallback <TService>(this IFeignClient feignClient)
        {
            IFallbackFeignClient <TService> fallbackFeignClient = feignClient.AsFallback <TService>();

            if (fallbackFeignClient == null)
            {
                return(default(TService));
            }
            return(fallbackFeignClient.Fallback);
        }
        public override IAsyncPolicy GetAsyncPolicy(IFeignClient <object> feignClient)
        {
            IAsyncPolicy asyncPolicy;

            if (_serviceTypePolicyMap.TryGetValue(feignClient.ServiceType, out asyncPolicy))
            {
                return(asyncPolicy);
            }
            return(_serviceTypePolicyMap.GetOrAdd(feignClient.ServiceType, type => SetupAllPolly(feignClient)));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceDiscoveryHttpClientHandler"/> class.
 /// </summary>
 public ServiceDiscoveryHttpClientHandler(IServiceDiscovery serviceDiscovery, IFeignClient feignClient, IGlobalFeignClientPipelineBuilder globalFeignClientPipeline, IDistributedCache distributedCache, ILogger logger)
 {
     _serviceResolve            = new RandomServiceResolve(logger);
     _feignClient               = feignClient;
     _globalFeignClientPipeline = globalFeignClientPipeline as GlobalFeignClientPipelineBuilder;
     _logger              = logger;
     _serviceDiscovery    = serviceDiscovery;
     _distributedCache    = distributedCache;
     ShouldResolveService = true;
 }
示例#11
0
        internal IAsyncPolicy SetupServiceIdPolly(IAsyncPolicy asyncPolicy, IFeignClient <object> feignClient)
        {
            List <Func <IAsyncPolicy, IAsyncPolicy> >         setups;
            List <Func <IAsyncPolicy, Task <IAsyncPolicy> > > asyncSetups;

            //serviceId
            if (_serviceIdPolicySetupsMap.TryGetValue(feignClient.ServiceId, out setups))
            {
                setups.ForEach(setup => asyncPolicy = setup.Invoke(asyncPolicy));
            }
            if (_serviceIdPolicyAsyncSetupsMap.TryGetValue(feignClient.ServiceId, out asyncSetups))
            {
                asyncSetups.ForEach(setup => asyncPolicy = setup.Invoke(asyncPolicy).ConfigureAwait(false).GetAwaiter().GetResult());
            }
            return(asyncPolicy);
        }
 internal CancelRequestEventArgs(IFeignClient feignClient, CancellationToken cancellationToken) : base(feignClient)
 {
     CancellationToken = cancellationToken;
 }
示例#13
0
 internal ReceivingResponseEventArgs(IFeignClient feignClient, HttpResponseMessage responseMessage, Type resultType) : base(feignClient)
 {
     ResponseMessage = responseMessage;
     ResultType      = resultType;
 }
 public InitializingEventArgs(IFeignClient feignClient) : base(feignClient)
 {
 }
 protected FeignClientEventArgs(IFeignClient <TService> feignClient)
 {
     FeignClient = feignClient;
 }
示例#16
0
 public virtual IAsyncPolicy GetAsyncPolicy(IFeignClient <object> feignClient)
 {
     return(SetupAllPolly(feignClient));
 }
 public FeignHttpRequestException(IFeignClient feignClient, FeignHttpRequestMessage requestMessage, Exception exception) : base(GetMessage(feignClient, requestMessage, exception), exception)
 {
     FeignClient    = feignClient;
     RequestMessage = requestMessage;
 }
示例#18
0
 public static TService GetFallback <TService>(this IFeignClient <TService> feignClient) where TService : class
 {
     return(feignClient.AsFallback()?.Fallback);
 }
示例#19
0
 internal SendingRequestEventArgs(IFeignClient feignClient, HttpRequestMessage requestMessage) : base(feignClient)
 {
     RequestMessage = requestMessage;
 }
 internal ErrorRequestEventArgs(IFeignClient feignClient, Exception exception) : base(feignClient)
 {
     Exception = exception;
 }
 public DisposingEventArgs(IFeignClient feignClient, bool disposing) : base(feignClient)
 {
     Disposing = disposing;
 }
 internal BuildingRequestEventArgs(IFeignClient feignClient, string method, Uri requestUri, IDictionary <string, string> headers) : base(feignClient)
 {
     Method     = method;
     RequestUri = requestUri;
     Headers    = headers;
 }
示例#23
0
 internal ReceivingResponseEventArgs(IFeignClient <TService> feignClient, FeignClientHttpRequest request, HttpResponseMessage responseMessage, Type resultType) : base(feignClient)
 {
     Request         = request;
     ResponseMessage = responseMessage;
     ResultType      = resultType;
 }
示例#24
0
        public static IFeignBuilder AddTestFeignClients(this IFeignBuilder feignBuilder)
        {
            Feign.FeignBuilderExtensions.AddConverter <TestServiceParam, string>(feignBuilder, new TestServiceParamStringConverter());
            feignBuilder.AddServiceDiscovery <TestServiceDiscovery>();
            feignBuilder.Options.IncludeMethodMetadata = true;
            Feign.FeignBuilderExtensions.AddFeignClients <IFeignBuilder>(feignBuilder, Assembly.GetExecutingAssembly(), FeignClientLifetime.Transient);
            feignBuilder.Options.FeignClientPipeline.Service <ITestService>().SendingRequest += (sender, e) =>
            {
                //e.Terminate();
            };
            feignBuilder.Options.FeignClientPipeline.Service <ITestControllerService>().SendingRequest += (sender, e) =>
            {
                //e.CancellationTokenSource.Cancel();
                //e.Terminate();
            };
            feignBuilder.Options.FeignClientPipeline.Service <ITestControllerService>().CancelRequest += (sender, e) =>
            {
                e.CancellationToken.Register(obj =>
                {
                    ICancelRequestEventArgs <ITestControllerService> ee = obj as ICancelRequestEventArgs <ITestControllerService>;
                    string s = ee.RequestMessage.ToString();
                }, e);
            };
            feignBuilder.Options.FeignClientPipeline.Service <ITestService>().SendingRequest += (sender, e) =>
            {
                var types = feignBuilder.Options.Types;
                if (e.RequestMessage.Content != null)
                {
                    MultipartFormDataContent multipartFormDataContent = e.RequestMessage.Content as MultipartFormDataContent;
                    if (multipartFormDataContent != null)
                    {
                        string boundary = multipartFormDataContent.Headers.ContentType.Parameters.FirstOrDefault(s => s.Name == "boundary").Value;
                        boundary = boundary.Replace("\"", "");
                        multipartFormDataContent.Headers.Remove("Content-Type");
                        multipartFormDataContent.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary);
                    }
                }
            };
            feignBuilder.Options.FeignClientPipeline.FallbackRequest += (sender, e) =>
            {
                var            parameters    = e.GetParameters();
                object         fallback      = e.Fallback;
                IFallbackProxy fallbackProxy = e.FallbackProxy;
                if (fallbackProxy == null)
                {
                    string s = "";
                }
                MethodInfo method = e.Method;
                e.Terminate();
            };
            feignBuilder.Options.FeignClientPipeline.Initializing += (sender, e) =>
            {
                ((HttpClientHandler)e.HttpClient.Handler.InnerHandler).AutomaticDecompression = DecompressionMethods.None | DecompressionMethods.GZip | DecompressionMethods.Deflate;
            };
            feignBuilder.Options.FeignClientPipeline.Service <ITestService>().Initializing += (sender, e) =>
            {
                e.FeignClient.Service.Name        = "Initializing set";
                e.FeignClient.Service.ServiceId   = e.FeignClient.ServiceId;
                e.FeignClient.Service.ServiceType = e.FeignClient.ServiceType;
            };
            feignBuilder.Options.FeignClientPipeline.Service("yun-platform-service-provider").Initializing += (sender, e) =>
            {
            };
            feignBuilder.Options.FeignClientPipeline.Disposing += (sender, e) =>
            {
                var ee = e;
            };
            //            feignBuilder.Options.FeignClientPipeline.Authorization(proxy =>
            //            {
            //#if NETSTANDARD
            //                return ("global", "asdasd");
            //#else
            //                return new AuthenticationHeaderValue("global", "asdasd");
            //#endif
            //            });
            feignBuilder.Options.FeignClientPipeline.BuildingRequest += FeignClientPipeline_BuildingRequest;
            feignBuilder.Options.FeignClientPipeline.Service <ITestService>().BuildingRequest += (sender, e) =>
            {
                IFeignClient <ITestService> feignClient = e.FeignClient as IFeignClient <ITestService>;
                ITestService service = feignClient.Service;
            };
            feignBuilder.Options.FeignClientPipeline.Service("yun-platform-service-provider").BuildingRequest += (sender, e) =>
            {
                var fallbackFeignClient = e.FeignClient.AsFallback <object>();
                fallbackFeignClient = e.FeignClient.AsFallback <object>();
                fallbackFeignClient = e.FeignClient.AsFallback <ITestService>();

                var fallback = fallbackFeignClient?.Fallback;

                fallback = e.FeignClient.GetFallback <object>();
                fallback = e.FeignClient.GetFallback <object>();
                //     fallback = e.FeignClient.GetFallback<ITestService>();

                if (!e.Headers.ContainsKey("Authorization"))
                {
                    e.Headers["Authorization"] = "service asdasd";
                }
                e.Headers["Accept-Encoding"] = "gzip, deflate, br";

                //add session
                e.Headers.Add("cookie", "csrftoken=EGxYkyZeT3DxEsvYsdR5ncmzpi9pmnQx; _bl_uid=nLjRstOyqOejLv2s0xtzqs74Xsmg; courseId=1; versionId=522; textbookId=2598; Hm_lvt_f0984c42ef98965e03c60661581cd219=1559783251,1559818390,1560213044,1560396804; uuid=6a30ff68-2b7c-4cde-a355-2e332b74e31d##1; Hm_lpvt_f0984c42ef98965e03c60661581cd219=1560413345; SESSION=5ee4854d-34b7-423a-9cca-76ddc8a0f111; sid=5ee4854d-34b7-423a-9cca-76ddc8a0f111");
            };
            //            feignBuilder.Options.FeignClientPipeline.Service<ITestService>().Authorization(proxy =>
            //            {
            //#if NETSTANDARD
            //                return ("service", "asdasd");
            //#else
            //                return new AuthenticationHeaderValue("service", "asdasd");
            //#endif
            //            });
            feignBuilder.Options.FeignClientPipeline.SendingRequest += FeignClientPipeline_SendingRequest;
            feignBuilder.Options.FeignClientPipeline.Service("yun-platform-service-provider").ReceivingResponse += (sender, e) =>
            {
            };
            feignBuilder.Options.FeignClientPipeline.Service <ITestService>().ReceivingQueryResult();
            feignBuilder.Options.FeignClientPipeline.CancelRequest += (sender, e) =>
            {
                e.CancellationToken.Register((state) =>
                {
                }, sender);
            };
            feignBuilder.Options.FeignClientPipeline.ErrorRequest += (sender, e) =>
            {
                Exception exception = e.Exception;
                //e.ExceptionHandled = true;
            };
            return(feignBuilder);
        }
 internal ErrorRequestEventArgs(IFeignClient <TService> feignClient, FeignHttpRequestMessage requestMessage, Exception exception) : base(feignClient)
 {
     RequestMessage = requestMessage;
     Exception      = exception;
 }
示例#26
0
 public static object GetFallback <TService>(this IFeignClient <object> feignClient) where TService : class
 {
     return(feignClient.AsFallback()?.Fallback as TService);
 }
示例#27
0
 internal DisposingEventArgs(IFeignClient <TService> feignClient, bool disposing) : base(feignClient)
 {
     Disposing = disposing;
 }
示例#28
0
 protected FeignClientEventArgs(IFeignClient feignClient)
 {
     FeignClient = feignClient;
 }
示例#29
0
 internal SendingRequestEventArgs(IFeignClient <TService> feignClient, FeignHttpRequestMessage requestMessage, CancellationToken cancellationToken) : base(feignClient)
 {
     RequestMessage     = requestMessage;
     _cancellationToken = cancellationToken;
 }
示例#30
0
 public static IFallbackFeignClient <TService> AsFallback <TService>(this IFeignClient <object> feignClient)
 {
     return(feignClient as IFallbackFeignClient <TService>);
 }