分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

feginclinet中设置hystrix的参数

发布时间:2023-09-06 02:13责任编辑:胡小海关键词:暂无标签
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的参数

原文地址:https://www.cnblogs.com/tiancai/p/9585023.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved