我正在尝试从 Hystrix 迁移到 Resilience4j 并尝试使用使用复原力4j-spring-boot2 依赖项的注释( https://resilience4j.readme.io/docs/getting-started-3 )配置弹性4j 的选项。
当我使用它进行测试并分析日志时,即使是用 @CircuitBreaker 修饰的方法也在同一个 http-nio 线程中运行:
带有 CircuitBreaker 注释的日志:
2020-01-10 10:31:15,996 [ http-nio-8080-exec-1 ] INFO APP=test-app | 环境=本地 | REQUEST_ID=1 | TRACE_ID=eb88d5c53ab97a40 | SPAN_ID=eb88d5c53ab97a40 | 客户 ID=1 | CLIENT_VERSION=1 | acsimpdependent.DependentApi - 请求:http ://example.api.com/api/customers/John
2020-01-10 10:31:15,997 [ http-nio-8080-exec-1 ] 调试 APP=test-app | 环境=本地 | REQUEST_ID=1 | TRACE_ID=eb88d5c53ab97a40 | SPAN_ID=eb88d5c53ab97a40 | 客户 ID=1 | CLIENT_VERSION=1 | acsimyservice.aop.LogingAspect - 输入:au.com.suncorp.insurance.myservice.config.DependentApiRestOperation.getRestOperations() 参数[s] = []
2020-01-10 10:31:15,999 [ http-nio-8080-exec-1 ] 调试 APP=test-app | 环境=本地 | REQUEST_ID=1 | TRACE_ID=eb88d5c53ab97a40 | SPAN_ID=eb88d5c53ab97a40 | 客户 ID=1 | CLIENT_VERSION=1 | acsimyservice.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 | 环境=本地 | REQUEST_ID=1 | TRACE_ID=eb88d5c53ab97a40 | SPAN_ID=eb88d5c53ab97a40 | 客户 ID=1 | CLIENT_VERSION=1 | acsimyservice.aop.LoggingAspect
相反,在这种情况下,当我从 CircuitBreakerFactory 创建一个 CircuitBreaker 时,我可以看到新的断路器线程在受断路器保护的方法内部控制时旋转。
CircuitBreakerFactory 的日志:
2020-01-10 10:50:04,178 [ hystrix-HystrixCircuitBreakerFactory-1 ] DEBUG APP=test-app | 环境=本地 | REQUEST_ID= | TRACE_ID=bde6e74d65833730 | SPAN_ID=d5dc68689645201a | 客户 ID= | CLIENT_VERSION= | acsimyservice.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 | 环境=本地 | REQUEST_ID= | TRACE_ID=bde6e74d65833730 | SPAN_ID=d5dc68689645201a | 客户 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 | 环境=本地 | REQUEST_ID= | TRACE_ID=bde6e74d65833730 | SPAN_ID=d5dc68689645201a | 客户 ID= | CLIENT_VERSION= | acsimyservice.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 | 环境=本地 | REQUEST_ID= | TRACE_ID=bde6e74d65833730 | SPAN_ID=d5dc68689645201a | 客户 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 | 环境=本地 | REQUEST_ID= | TRACE_ID=bde6e74d65833730 | SPAN_ID=d5dc68689645201a | 客户 ID= | CLIENT_VERSION= | acsimpdependent.DependentApi - 请求:http ://example.api.com/api/customers/John
2020-01-10 10:50:04,186 [ hystrix-HystrixCircuitBreakerFactory-1 ] DEBUG APP=test-app | 环境=本地 | REQUEST_ID= | TRACE_ID=bde6e74d65833730 | SPAN_ID=d5dc68689645201a | 客户 ID= | CLIENT_VERSION= | acsimyservice.aop.LoggingAspect - 输入:au.com.suncorp.insurance.myservice.config.DependentApiRestOperation.getRestOperations() 参数[s] = []