public static IFeignBuilder AddDiscoveryClient(this IFeignBuilder feignBuilder)
 {
     return(feignBuilder.AddServiceDiscovery <SteeltoeServiceDiscovery>());
 }
示例#2
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);
        }