我正在尝试从Hystrix迁移到Resilience4j,并尝试了使用注释(https://resilience4j.readme.io/docs/getting-started-3)配置resilience4j的选项,该注释使用了resilience4j-spring-boot2依赖项。
当我使用它进行测试并分析日志时,即使使用@CircuitBreaker装饰的方法也在同一http-nio线程中运行:
带有CircuitBreaker批注的日志:
2020-01-10 10:31:15,996 [ http-nio-8080-exec-1 ] INFO APP = test-app | ENV = LOCAL | REQUEST_ID = 1 | TRACE_ID = eb88d5c53ab97a40 | SPAN_ID = eb88d5c53ab97a40 | CLIENT_ID = 1 | CLIENT_VERSION = 1 | a.c.s.i.m.p.dependent.DependentApi-请求:http://example.api.com/api/customers/John
2020-01-10 10:31:15,997 [ http-nio-8080-exec-1 ] DEBUG APP = test-app | ENV = LOCAL | REQUEST_ID = 1 | TRACE_ID = eb88d5c53ab97a40 | SPAN_ID = eb88d5c53ab97a40 | CLIENT_ID = 1 | CLIENT_VERSION = 1 | a.c.s.i.myservice.aop.LogingAspect-输入:au.com.suncorp.insurance.myservice.config.DependentApiRestOperation.getRestOperations(),参数为[s] = []
2020-01-10 10:31:15,999 [ http-nio-8080-exec-1 ] DEBUG APP = test-app | ENV = LOCAL | REQUEST_ID = 1 | TRACE_ID = eb88d5c53ab97a40 | SPAN_ID = eb88d5c53ab97a40 | CLIENT_ID = 1 | CLIENT_VERSION = 1 | a.c.s.i.myservice.aop.LoggingAspect-退出:au.com.suncorp.insurance.myservice.config.DependentApiRestOperation.getRestOperations(),结果为org.springframework.web.client.RestTemplate@1f3111d1
2020-01-10 10:31:16,065 [ http-nio-8080-exec-1 ]错误APP = test-app | ENV = LOCAL | REQUEST_ID = 1 | TRACE_ID = eb88d5c53ab97a40 | SPAN_ID = eb88d5c53ab97a40 | CLIENT_ID = 1 | CLIENT_VERSION = 1 | a.c.s.i.myservice.aop.LoggingAspect
相反,在那种情况下,当我从CircuitBreakerFactory创建CircuitBreaker时,当控件中的控件受断路器保护时,我可以看到新的断路器线程旋转起来。
CircuitBreakerFactory的日志:
2020-01-10 10:50:04,178 [ hystrix-HystrixCircuitBreakerFactory-1 ] DEBUG APP = test-app | ENV = LOCAL | REQUEST_ID = | TRACE_ID = bde6e74d65833730 | SPAN_ID = d5dc68689645201a | CLIENT_ID = | CLIENT_VERSION = | a.c.s.i.myservice.aop.LoggingAspect-输入:au.com.suncorp.insurance.myservice.config.properties.DependentApiProperties.getAddress(),参数为[s] = []
2020-01-10 10:50:04,178 [ hystrix-HystrixCircuitBreakerFactory-1 ] DEBUG APP = test-app | ENV = LOCAL | REQUEST_ID = | TRACE_ID = bde6e74d65833730 | SPAN_ID = d5dc68689645201a | CLIENT_ID = | CLIENT_VERSION = | acsimyservice.aop.LoggingAspect-退出:au.com.suncorp.insurance.myservice.config.properties.DependentApiProperties.getAddress(),结果= au.com.suncorp.insurance.myservice.config.properties.DependentApiProperties$Address@1928e7f3
2020-01-10 10:50:04,179 [ hystrix-HystrixCircuitBreakerFactory-1 ] DEBUG APP = test-app | ENV = LOCAL | REQUEST_ID = | TRACE_ID = bde6e74d65833730 | SPAN_ID = d5dc68689645201a | CLIENT_ID = | CLIENT_VERSION = | a.c.s.i.myservice.aop.LoggingAspect-输入:au.com.suncorp.insurance.myservice.config.properties.DependentApiProperties.getAddress(),参数为[s] = []
2020-01-10 10:50:04,179 [ hystrix-HystrixCircuitBreakerFactory-1 ] DEBUG APP = test-app | ENV = LOCAL | REQUEST_ID = | TRACE_ID = bde6e74d65833730 | SPAN_ID = d5dc68689645201a | CLIENT_ID = | CLIENT_VERSION = | acsimyservice.aop.LoggingAspect-退出:au.com.suncorp.insurance.myservice.config.properties.DependentApiProperties.getAddress(),结果= au.com.suncorp.insurance.myservice.config.properties.DependentApiProperties$Address@1928e7f3
2020-01-10 10:50:04,184 [ hystrix-HystrixCircuitBreakerFactory-1 ] INFO APP = test-app | ENV = LOCAL | REQUEST_ID = | TRACE_ID = bde6e74d65833730 | SPAN_ID = d5dc68689645201a | CLIENT_ID = | CLIENT_VERSION = | a.c.s.i.m.p.dependent.DependentApi-请求:http://example.api.com/api/customers/John
2020-01-10 10:50:04,186 [ hystrix-HystrixCircuitBreakerFactory-1 ] DEBUG APP = test-app | ENV = LOCAL | REQUEST_ID = | TRACE_ID = bde6e74d65833730 | SPAN_ID = d5dc68689645201a | CLIENT_ID = | CLIENT_VERSION = | a.c.s.i.myservice.aop.LoggingAspect-输入:au.com.suncorp.insurance.myservice.config.DependentApiRestOperation.getRestOperations(),参数为[s] = []
答案 0 :(得分:1)
Resilience4j Spring Boot Starter和Spring Cloud CircuitBreaker是两个不同/分离的项目。
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和基于Threadpool的Bulkhead是两种不同的弹性模式,您可能需要结合或不结合。如果要合并它们,则必须对方法应用两个注释-> @CircuitBreaker
和@Bulkhead(type = Type.THREADPOOL)
。
看一下演示-> https://github.com/resilience4j/resilience4j-spring-boot2-demo