为什么Resilience4j断路器不能启动新的线程



我正试图从Hystrix迁移到Resilience4j,并尝试了使用注释配置Resiliece4j的选项(https://resilience4j.readme.io/docs/getting-started-3)其使用弹性4j-spring-bot2依赖性。

当我使用它进行测试并分析日志时,即使是用@CircuitBreaker装饰的方法也在同一个http nio线程中运行:

带有CircuitBreaker注释的日志:


2020-01-10 10:31:15996[http-nio-8080-exec-1]INFO APP=测试应用程序|ENV=本地|REQUEST_ID=1|TRACE_ID=eb88d5c53ab97a40|SPAN_ID=eb88d 5c53ab976a40|CLIENT_ID=1| CLIENT_VERSION=1 |a.c.si.m.p.dependent.DependentApi-请求:http://example.api.com/api/customers/John

2020-01-10 10:31:15997[http-nio-8080-exec-1]调试APP=测试应用程序|ENV=LOCAL|REQUEST_ID=1|TRACE_ID=eb88d5c53ab97a40|SPAN_ID=eb88d 5c53ab976a40|CLIENT_ID=1| CLIENT_VERSION=1|a.cs.i.myservice.aop.LogingAspect-输入:au.com.suncorp.sinsurance.myservice.config.DependentApiRestOperation.getRestOperations(),参数[s]=[]

2020-01-10 10:31:15999[http-nio-8080-exec-1]调试应用程序=测试应用程序|ENV=LOCAL|REQUEST_ID=1|TRACE_ID=eb88d5c53ab97a40|SPAN_ID=eb88d 5c53ab976a40|CLIENT_ID=1| CLIENT_VERSION=1|a.cs.i.myservice.aop.LoggingAspect-退出:au.com.suncorp.sinsurance.myservice.config.DependentApiRestOperation.getRestOperations(),结果=org.springframework.web.client.RestTemplate@1f3111d1

2020-01-10 10:31:16065[http-nio-8080-exec-1]错误APP=测试应用程序|ENV=LOCAL|REQUEST_ID=1|TRACE_ID=eb88d5c53ab97a40|SPAN_ID=eb88d 5c53ab976a40|CLIENT_ID=1| CLIENT_VERSION=1|a.cs.i.myservice.aop.LoggingAspect


相反,当我从CircuitBreakerFactory创建CircuitBreaker时,在这种情况下,当断路器保护的方法中的控件时,我可以看到新的断路器线程正在旋转。

CircuitBreakerFactory的日志:


2020-01-10 10:50:04178[hystrix-HystrixCircuitBreakerFactory-1]调试应用程序=测试应用程序|ENV=LOCAL|REQUEST_ID=|TRACE_ID=bde6e74d65833730|SPAN_ID=d5dc68689645201a|CLIENT_ID=|CLIENT_VERSION=|a.cs.i.myservice.aop.LoggingAspect-输入:au.com.suncorp.sinsurance.myservice.config.properties.DependentApiProperties.getAddress(),参数[s]=[]

2020-01-10 10:50:04178[hystrix-HystrixCircuitBreakerFactory-1]调试应用程序=测试应用程序|ENV=LOCAL|REQUEST_ID=|TRACE_ID=bde6e74d65833730|SPAN_ID=d5dc68689645201a|CLIENT_ID=|CLIENT_VERSION=|a.c.si.myservice.aop.LoggingAspect-退出:au.com.suncorp.sensurance.myservice.config.properties.DependentApiProperties.getAddress(),结果=au.com.suncorp.insurance.myservice.config.properties依赖ApiProperties$Address@1928e7f3

2020-01-10 10:50:04179[hystrix-HystrixCircuitBreakerFactory-1]调试应用程序=测试应用程序|ENV=LOCAL|REQUEST_ID=|TRACE_ID=bde6e74d65833730|SPAN_ID=d5dc68689645201a|CLIENT_ID=|CLIENT_VERSION=|a.cs.i.myservice.aop.LoggingAspect-输入:au.com.suncorp.sensurance.myservice.config.properties.DependentApiProperties.getAddress(),参数[s]=[]

2020-01-10 10:50:04179[hystrix-HystrixCircuitBreakerFactory-1]调试应用程序=测试应用程序|ENV=LOCAL|REQUEST_ID=|TRACE_ID=bde6e74d65833730|SPAN_ID=d5dc68689645201a|CLIENT_ID=|CLIENT_VERSION=|a.c.si.myservice.aop.LoggingAspect-退出:au.com.suncorp.sensurance.myservice.config.properties.DependentApiProperties.getAddress(),结果=au.com.suncorp.insurance.myservice.config.properties依赖ApiProperties$Address@1928e7f3

2020-01-10 10:50:04184[hystrix-HystrixCircuitBreakerFactory-1]INFO APP=测试应用程序|ENV=本地|REQUEST_ID=|TRACE_ID=bde6e74d65833730|SPAN_ID=d5dc68689645201a|CLIENT_ID=|CLIENT_VERSION=|a.c.i.m.p.dependent.DependentApi-请求:http://example.api.com/api/customers/John

2020-01-10 10:50:04186[hystrix-HystrixCircuitBreakerFactory-1]调试应用程序=测试应用程序|ENV=LOCAL|REQUEST_ID=|TRACE_ID=bde6e74d65833730|SPAN_ID=d5dc68689645201a|CLIENT_ID=|CLIENT_VERSION=|a.cs.i.myservice.aop.LoggingAspect-输入:au.com.suncorp.sensurance.myservice.config.DependentApiRestOperation.getRestOperations(),参数[s]=[]


弹性4j弹簧启动启动器和弹簧云断路器是两个不同/独立的项目。

Spring Cloud CircuitBreaker在单独的线程池中运行方法。请参阅->https://github.com/spring-cloud/spring-cloud-circuitbreaker/blob/master/spring-cloud-circuitbreaker-resilience4j/src/main/java/org/springframework/cloud/circuitbreaker/resilience4j/Resilience4JCircuitBreaker.java#L68

在Resilience4j和Spring Boot Starter中,CircuitBreaker和基于线程池的Bulkhead是两种不同的弹性模式,您可能希望将其组合或不组合。如果你想将它们组合起来,你必须对你的方法应用两个注释->@CircuitBreaker@Bulkhead(type = Type.THREADPOOL)

看看演示->https://github.com/resilience4j/resilience4j-spring-boot2-demo

最新更新