zoukankan      html  css  js  c++  java
  • feginclinet中设置hystrix的参数

    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) // 超时配置
                            );
                }
            });
        }
    
    
    }
  • 相关阅读:
    IOS数组
    caffe-fasterrcnn程序理解
    pytorch官网上两个例程
    python:批量修改文件名批量修改图片尺寸
    faster rcnn报错:TypeError: slice indices must be integers or None or have an __index__ method
    faster-rcnn原理讲解
    caffe + ssd网络训练过程
    运行Keras版本的Faster R-CNN(1)
    Ubuntu16.04 faster-rcnn+caffe+gpu运行环境配置以及解决各种bug
    ubuntu16+caffe fast-rcnnCPU运行步骤
  • 原文地址:https://www.cnblogs.com/tiancai/p/9585023.html
Copyright © 2011-2022 走看看