feginclinet中設定hystrix的參數

來源:互聯網
上載者:User

標籤:clinet   ram   auto   second   new   fegin   pac   set   reflect   

package com.example.demo;import com.netflix.hystrix.HystrixCommand;//import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;import com.netflix.hystrix.HystrixCommandGroupKey;import com.netflix.hystrix.HystrixCommandProperties;import feign.Feign;import feign.Request;import feign.Retryer;import feign.Target;import feign.hystrix.HystrixFeign;import feign.hystrix.SetterFactory;import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.Scope;import java.lang.reflect.Method;@Configuration@ConditionalOnClass({ HystrixCommand.class, HystrixFeign.class })public class FeginConfiguration {    public static int connectTimeOutMillis = 5000;//逾時時間    public static int readTimeOutMillis = 5000;    @Bean    public Request.Options options() {        return new Request.Options(connectTimeOutMillis, readTimeOutMillis);    }    //自訂重試次數    @Bean    public Retryer feignRetryer(){        Retryer retryer = new Retryer.Default(100, 1000, 4);        return retryer;    }    //hystrix  逾時時間    @Bean    public Feign.Builder feignHystrixBuilder() {        return HystrixFeign.builder().setterFactory(new SetterFactory() {            @Override            public HystrixCommand.Setter create(Target<?> target, Method method) {                return HystrixCommand.Setter                        .withGroupKey(HystrixCommandGroupKey.Factory.asKey(SchedualServiceHi.class.getSimpleName()))// 控制 RemoteProductService 下,所有方法的Hystrix Configuration                        .andCommandPropertiesDefaults(                                HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(10000) // 逾時配置                        );            }        });    }}

 

feginclinet中設定hystrix的參數

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.