博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SleuthHystrixFeign 怎么设置hystrix参数
阅读量:6835 次
发布时间:2019-06-26

本文共 5391 字,大约阅读时间需要 17 分钟。

hot3.png

@Configuration@ConditionalOnProperty(value = "spring.sleuth.feign.enabled", matchIfMissing = true)@ConditionalOnClass(Client.class)@ConditionalOnBean(Tracer.class)@AutoConfigureBefore(FeignAutoConfiguration.class)@AutoConfigureAfter({SleuthHystrixAutoConfiguration.class, TraceWebAutoConfiguration.class})public class TraceFeignClientAutoConfiguration {    /**     默认一秒超时,hystrix.     当启动spring.sleuth.enabled=true 会启用配置,SleuthHystrixFeignBuilder.builder从代码层面没法重写该访问,要想设置hystrix超时时间,只能通过配置:   1.hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=7000   2.重写该配置类    *    /	@Bean	@Scope("prototype")	@ConditionalOnClass(name = "com.netflix.hystrix.HystrixCommand")	@ConditionalOnProperty(name = "feign.hystrix.enabled", matchIfMissing = true)	Feign.Builder feignHystrixBuilder(BeanFactory beanFactory) {		return SleuthHystrixFeignBuilder.builder(beanFactory);	}	@Bean	@ConditionalOnMissingBean	@Scope("prototype")	@ConditionalOnProperty(name = "feign.hystrix.enabled", havingValue = "false", matchIfMissing = false)	Feign.Builder feignBuilder(BeanFactory beanFactory) {		return SleuthFeignBuilder.builder(beanFactory);	}	@Configuration	@ConditionalOnProperty(name = "spring.sleuth.feign.processor.enabled", matchIfMissing = true)	protected static class FeignBeanPostProcessorConfiguration {		@Bean		FeignBeanPostProcessor feignBeanPostProcessor(TraceFeignObjectWrapper traceFeignObjectWrapper) {			return new FeignBeanPostProcessor(traceFeignObjectWrapper);		}		@Bean		FeignContextBeanPostProcessor feignContextBeanPostProcessor(BeanFactory beanFactory) {			return new FeignContextBeanPostProcessor(beanFactory);		}	}	@Bean	TraceFeignObjectWrapper traceFeignObjectWrapper(BeanFactory beanFactory) {		return new TraceFeignObjectWrapper(beanFactory);	}}

配置:

feign.hystrix.enabled=true

spring.sleuth.enabled=true

 

日志:

dominos-pe | 2019-04-10 15:00:02.362 | hystrix-dominos-im-1 | DEBUG | o.s.c.s.i.h.SleuthHystrixConcurrencyStrategy$HystrixTraceCallable.call(142) | Creating new span [Trace: 6b2b0946e4957196, Span: 6b2b0946e4957196, Parent: null, exportable:false]dominos-pe | 2019-04-10 15:00:02.391 | hystrix-dominos-im-1 | DEBUG | o.s.b.f.s.DefaultListableBeanFactory.doGetBean(251) | Returning cached instance of singleton bean 'messageConverters'dominos-pe | 2019-04-10 15:00:02.391 | hystrix-dominos-im-1 | DEBUG | o.s.c.n.feign.support.SpringEncoder.encode(77) | Writing [123132] using [org.springframework.http.converter.StringHttpMessageConverter@b548f51]dominos-pe | 2019-04-10 15:00:02.398 | hystrix-dominos-im-1 | DEBUG | o.s.b.f.s.DefaultListableBeanFactory.doGetBean(251) | Returning cached instance of singleton bean 'sleuthTracer'dominos-pe | 2019-04-10 15:00:02.398 | hystrix-dominos-im-1 | DEBUG | o.s.c.s.i.w.c.feign.TraceFeignClient.execute(69) | Created new Feign span [Trace: 6b2b0946e4957196, Span: 25fdbf1bf842dd8f, Parent: 6b2b0946e4957196, exportable:false]dominos-pe | 2019-04-10 15:00:02.400 | hystrix-dominos-im-1 | DEBUG | o.s.b.f.s.DefaultListableBeanFactory.doGetBean(251) | Returning cached instance of singleton bean 'httpTraceKeysInjector'dominos-pe | 2019-04-10 15:00:02.400 | hystrix-dominos-im-1 | DEBUG | o.s.c.s.i.w.c.feign.TraceFeignClient.execute(78) | The modified request equals POST http://localhost:9005/product/queryCategoriesCodeByProductCode HTTP/1.1X-Span-Name: http:/product/queryCategoriesCodeByProductCodeX-B3-SpanId: 25fdbf1bf842dd8fX-B3-ParentSpanId: 6b2b0946e4957196X-B3-Sampled: 0X-B3-TraceId: 6b2b0946e4957196Content-Length: 6Content-Type: text/plain;charset=UTF-8123132dominos-pe | 2019-04-10 15:00:05.510 | hystrix-dominos-im-1 | DEBUG | o.s.c.s.i.w.c.feign.TraceFeignClient.closeSpan(119) | Closing Feign span [Trace: 6b2b0946e4957196, Span: 25fdbf1bf842dd8f, Parent: 6b2b0946e4957196, exportable:false]dominos-pe | 2019-04-10 15:00:05.510 | hystrix-dominos-im-1 | DEBUG | o.s.c.s.zipkin.ZipkinSpanListener.report(216) | The span [Trace: 6b2b0946e4957196, Span: 25fdbf1bf842dd8f, Parent: 6b2b0946e4957196, exportable:false] will not be sent to Zipkin due to samplingdominos-pe | 2019-04-10 15:00:05.516 | hystrix-dominos-im-1 | DEBUG | com.netflix.hystrix.AbstractCommand.handleFailureViaFallback(1010) | Error executing HystrixCommand.run(). Proceeding to fallback logic ...
@Configurationpublic class CommonHystrixConfiguration {	/**	 * hystrix 超时时间	 */	static int hystrixTimeOut = 10000;	/**	 * 请求超时时间	 */	static int requestTimeOut = 3000;		@Bean	public Request.Options options() {		return new Request.Options(requestTimeOut, requestTimeOut);	}	@Bean	Retryer feignRetryer() {		return new Retryer.Default(100, SECONDS.toMillis(1), 1);	}//此配置无效,因为用的是TraceFeignClientAutoConfiguration种的feignHystrixBuilder,默认超时是1秒,只能通过配置文件配置	@Bean	public Feign.Builder feignHystrixBuilder() {		return HystrixFeign.builder().setterFactory(new SetterFactory() {			public HystrixCommand.Setter create(Target
target, Method method) { String groupKey = target.name(); String commandKey = method.getName(); return HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)).andCommandPropertiesDefaults( HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(hystrixTimeOut) .withCircuitBreakerSleepWindowInMilliseconds(hystrixTimeOut) ); } }); }}

 

转载于:https://my.oschina.net/xiaominmin/blog/3034649

你可能感兴趣的文章
phpunit mock
查看>>
NodeJS、NPM安装配置步骤(windows版本)
查看>>
mac常用的命令
查看>>
knn 分类
查看>>
【总结】Hadoop中的MultipleOutputs实践
查看>>
测试常见问题
查看>>
SHOP++ 中Hibernate 注解 用法
查看>>
jQuery EasyUI使用教程之创建基本的树网格
查看>>
Fluentd日志处理-插件使用和调试问题(四)
查看>>
实验四 交换机SPAN功能配置 (交换与路由技术)
查看>>
centos7源码安装php5.6并安装pthreads扩展
查看>>
网络基础~linux路由与网关、路由命令
查看>>
强大的联想4U机架式服务器ThinkSystem SR950
查看>>
美国防部:美国×××防御系统存在诸多安全问题
查看>>
阿里云搭建lamp平台
查看>>
Reverse Integer之Java实现
查看>>
Linux的SSH服务初学
查看>>
不同于FTP的另一款文件传输工具
查看>>
MYSQL 逻辑架构
查看>>
第11课--11_04_Linux网络配置之四 ifconfig及ip命令详解
查看>>