internal FallbackRequestEventArgs(IFeignClient <TService> feignClient, FeignClientHttpRequest request, TService fallback, IFallbackProxy fallbackProxy, MethodInfo method) : base(feignClient)
 {
     Request       = request;
     Fallback      = fallback;
     FallbackProxy = fallbackProxy;
     _method       = method;
 }
 public FallbackRequestEventArgs(IFeignClient feignClient, FeignClientRequest request, object fallback, IFallbackProxy fallbackProxy, MethodInfo method) : base(feignClient)
 {
     Request       = request;
     Fallback      = fallback;
     FallbackProxy = fallbackProxy;
     _method       = method;
 }
        /// <summary>
        /// 触发服务降级事件
        /// </summary>
        /// <param name="request"></param>
        /// <param name="delegate"></param>
        /// <param name="serviceResolveFailException"></param>
        /// <returns></returns>
        bool InvokeFallbackRequestPipeline(FeignClientHttpRequest request, Delegate @delegate, ServiceResolveFailException serviceResolveFailException)
        {
            IFallbackProxy fallbackProxy = @delegate.Target as IFallbackProxy;
            FallbackRequestEventArgs <TService> eventArgs;

            if (fallbackProxy == null)
            {
                //可能因为method parameters length=0 , 故没有生成匿名调用类
                eventArgs = new FallbackRequestEventArgs <TService>(this, request, Fallback, null, @delegate.Method);
            }
            else
            {
                eventArgs = new FallbackRequestEventArgs <TService>(this, request, Fallback, fallbackProxy, null);
            }
            OnFallbackRequest(eventArgs);
            return(eventArgs.IsTerminated);
        }
Ejemplo n.º 4
0
        bool InvokeFallbackRequestPipeline(FeignClientRequest request, Delegate @delegate)
        {
            IFallbackProxy           fallbackProxy = @delegate.Target as IFallbackProxy;
            FallbackRequestEventArgs eventArgs;

            if (fallbackProxy == null)
            {
                //可能因为method parameters length=0 , 故没有生成匿名调用类
                eventArgs = new FallbackRequestEventArgs(this, request, _fallback, null, @delegate.Method);
            }
            else
            {
                eventArgs = new FallbackRequestEventArgs(this, request, _fallback, fallbackProxy, null);
            }
            OnFallbackRequest(eventArgs);
            return(eventArgs.IsTerminated);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public static IFeignBuilder AddTestFeignClients(this IFeignBuilder feignBuilder)
        {
            //feignBuilder.Options.IncludeMethodMetadata = true;
            feignBuilder.AddFeignClients(Assembly.GetExecutingAssembly(), FeignClientLifetime.Singleton);
            feignBuilder.Options.FeignClientPipeline.Service <ITestService>().SendingRequest += (sender, e) =>
            {
                //e.Terminate();
            };
            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) =>
            {
            };
            feignBuilder.Options.FeignClientPipeline.Service("yun-platform-service-provider").Initializing += (sender, e) =>
            {
            };
            feignBuilder.Options.FeignClientPipeline.Disposing += (sender, 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) =>
            {
                IFallbackFeignClient fallbackFeignClient = e.FeignClient.AsFallback();
                fallbackFeignClient = e.FeignClient.AsFallback <object>();
                fallbackFeignClient = e.FeignClient.AsFallback <ITestService>();

                var fallback = fallbackFeignClient?.Fallback;

                fallback = e.FeignClient.GetFallback();
                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("yun-platform-service-provider").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.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);
        }