spring cloud 遇到配置问题解决方法

摘要:自己学习spring cloud,遇到很多问题,LZ网上找到资料解决了,也不知道解决方法怎么样,反正解决了,有好的意见请留言

第一种 Feign调用服务请求超时

LZ用Feign调用其他服务,在controller里面手动休眠了几秒,就报超时,大概错误如下

java.util.concurrent.TimeoutException: null
    at com.netflix.hystrix.AbstractCommand.handleTimeoutViaFallback(AbstractCommand.java:980) ~[hystrix-core-1.5.6.jar:1.5.6]
    at com.netflix.hystrix.AbstractCommand.access$500(AbstractCommand.java:59) ~[hystrix-core-1.5.6.jar:1.5.6]
    at com.netflix.hystrix.AbstractCommand$12.call(AbstractCommand.java:595) ~[hystrix-core-1.5.6.jar:1.5.6]
    at com.netflix.hystrix.AbstractCommand$12.call(AbstractCommand.java:587) ~[hystrix-core-1.5.6.jar:1.5.6]
    at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$4.onError(OperatorOnErrorResumeNextViaFunction.java:140) ~[rxjava-1.1.10.jar:1.1.10]
    at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87) ~[rxjava-1.1.10.jar:1.1.10]

解决方案,在application.yml添加如下配置

hystrix:
  command:
    default:
      execution:
         timeout:
            enabled: false

说明:

#加大熔断器检测时间(默认1秒)
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 5000
#关闭熔断器超时检测时间功能,也就是不超时(上面用的就是此方法)
hystrix.command.default.execution.timeout.enabled: false
#直接禁用feign的hystrix (一般不建议)
feign.hystrix.enabled: false

第二种是Feign调用服务报线程池的问题

LZ想摸你雪崩效应,但是每次用jmeter工具设置1秒向服务器请求50次,就一直报线程的问题,大概如下

java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@1a79348a rejected from java.util.concurrent.ThreadPoolExecutor@5dccbd14[Running, pool size = 10, active threads = 10, queued tasks = 0, completed tasks = 0]
    at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2047) ~[na:1.8.0_65]
    at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:823) [na:1.8.0_65]
    at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1369) [na:1.8.0_65]
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112) ~[na:1.8.0_65]

解决方法,在application.yml 加入如下配置,加大线程数(多大,看你的测试环境)

hystrix:
  threadpool:
    default:
      coreSize: 51

LZ改为51,大于我的模拟并发数,这个错误就没有了,哪个老铁有更好的方法,望告知!!

后续有问题继续更新

你可能感兴趣的:(spring)