feign feign.hystrix.enabled=false spring.sleuth.enabled=false 的超时时间和重试次数

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

相当于是单http请求
feign.hystrix.enabled=false  不启动hystrix
spring.sleuth.enabled=false 不启用链路追踪

异常:
feign.RetryableException: timeout executing POST http://localhost:9005/product/queryCategoriesCodeByProductCode
    at feign.FeignException.errorExecuting(FeignException.java:67)
    at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:104)
    at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76)
    at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103)
    at com.sun.proxy.$Proxy115.queryCategoriesCodeByProductCode2(Unknown Source)
    at com.dominos.cloud.pe.service.IProductServiceTest.tes3t(IProductServiceTest.java:40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: java.net.SocketTimeoutException: timeout
    at okio.Okio$4.newTimeoutException(Okio.java:232)
    at okio.AsyncTimeout.exit(AsyncTimeout.java:285)
    at okio.AsyncTimeout$2.read(AsyncTimeout.java:241)
    at okio.RealBufferedSource.indexOf(RealBufferedSource.java:355)
    at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:227)
    at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:221)
    at okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:184)
    at okhttp3.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:125)
    at okhttp3.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:775)
    at okhttp3.internal.http.HttpEngine.access$200(HttpEngine.java:86)
    at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:760)
    at okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:613)
    at okhttp3.RealCall.getResponse(RealCall.java:244)
    at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163)
    at okhttp3.RealCall.execute(RealCall.java:57)
    at feign.okhttp.OkHttpClient.execute(OkHttpClient.java:157)
    at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:97)
    ... 33 more
Caused by: java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.socketRead(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at okio.Okio$2.read(Okio.java:140)
    at okio.AsyncTimeout$2.read(AsyncTimeout.java:237)
    ... 48 more
时间:316530

源码:

feign.SynchronousMethodHandler.invoke(Object[])

 @Override
  public Object invoke(Object[] argv) throws Throwable {
    RequestTemplate template = buildTemplateFromArgs.create(argv);
    Retryer retryer = this.retryer.clone();//最大重试次数是5次
    while (true) {
      try {
        return executeAndDecode(template);
      } catch (RetryableException e) {
        retryer.continueOrPropagate(e);
        if (logLevel != Logger.Level.NONE) {
          logger.logRetry(metadata.configKey(), logLevel);
        }
        continue;
      }
    }
  }
  
  feign.SynchronousMethodHandler.executeAndDecode(RequestTemplate)
  
   response = client.execute(request, options);

    feign.Request.Options
   public static class Options {

    private final int connectTimeoutMillis;
    private final int readTimeoutMillis;

    public Options(int connectTimeoutMillis, int readTimeoutMillis) {
      this.connectTimeoutMillis = connectTimeoutMillis;
      this.readTimeoutMillis = readTimeoutMillis;
    }

    //默认是一分钟
    public Options() {
      this(10 * 1000, 60 * 1000);
    }
    
    
//配置

@Bean
    public Request.Options options() {
        return new Request.Options(10000 * 1, 10000 * 1);
    }

	@Bean
	Retryer feignRetryer() {
	    return Retryer.NEVER_RETRY;
	}
	
	
	@Bean
	   public Feign.Builder feignHystrixBuilder() {
	        return HystrixFeign.builder().setterFactory(new SetterFactory() {
	            public HystrixCommand.Setter create(Target target, Method method) {
	            	   String groupKey = target.name();
	            	   //@FeignClient(name = "dominos-im"
	            	   System.out.println(groupKey);
	            	   String commandKey = method.getName();
	            	   System.out.println("commandKey=="+commandKey);
	            	   
	            	   int time = 12000;
	                return HystrixCommand.Setter
	                        .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))// 控制 RemoteProductService 下,所有方法的Hystrix Configuration
	                        .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey))
	                        .andCommandPropertiesDefaults(
	                                HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(time)
	                                .withCircuitBreakerSleepWindowInMilliseconds(time)// 超时配置
	                        );
	            }
	        });
	    }

 

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

你可能感兴趣的:(feign feign.hystrix.enabled=false spring.sleuth.enabled=false 的超时时间和重试次数)