Java/Spring: 如何找到打开Resilence4J断路器的错误?

Java/Spring: How to find what error opened the Resilence4J circuit breaker?

我正在使用 Resilence4j 断路器和 Spring 引导,如下所示:

import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;

@Component
@CircuitBreaker(name = "ExternalService")
public class ExternalServiceClient implements APIClient {
     //....
}

我没有在我的 application.yml 中指定任何其他配置,因此断路器使用默认值运行。每当断路器打开时,我都会看到如下错误:

Failure to call external service  for entity id 12343
   stack_trace: io.github.resilience4j.circuitbreaker.CallNotPermittedException: CircuitBreaker 'ExternalService' is OPEN and does not permit further calls
    at io.github.resilience4j.circuitbreaker.CallNotPermittedException.createCallNotPermittedException(CallNotPermittedException.java:37) ~[resilience4j-circuitbreaker-1.1.0.jar!/:1.1.0]
    at io.github.resilience4j.circuitbreaker.internal.CircuitBreakerStateMachine$HalfOpenState.acquirePermission(CircuitBreakerStateMachine.java:685)
    at io.github.resilience4j.circuitbreaker.internal.CircuitBreakerStateMachine.acquirePermission(CircuitBreakerStateMachine.java:146)
    at io.github.resilience4j.circuitbreaker.CircuitBreaker.lambda$decorateCheckedSuppliera9021a(CircuitBreaker.java:599)
    at io.github.resilience4j.circuitbreaker.CircuitBreaker.executeCheckedSupplier(CircuitBreaker.java:340)
    at io.github.resilience4j.circuitbreaker.configure.CircuitBreakerAspect.defaultHandling(CircuitBreakerAspect.java:155) ~[resilience4j-spring-0.16.0.jar!/:0.16.0]
    at io.github.resilience4j.circuitbreaker.configure.CircuitBreakerAspect.proceed(CircuitBreakerAspect.java:115)
    at io.github.resilience4j.circuitbreaker.configure.CircuitBreakerAspect.circuitBreakerAroundAdvice(CircuitBreakerAspect.java:98)
    at jdk.internal.reflect.GeneratedMethodAccessor238.invoke(Unknown Source) ~[na:na]
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:566)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644) ~[spring-aop-5.2.5.RELEASE.jar!/:5.2.5.RELEASE]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)
    at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)

这告诉我断路器由于某些错误情况而打开(因此不再允许调用)但没有具体说明原始错误是什么。有没有办法找出原始错误?是否有我应该在日志中查找的特定文本,或者是否有一些我需要打开的设置,以便此错误也告诉我断路器打开的最初原因?

CallNotPermittedException 和底层堆栈跟踪发生在断路器打开后的状态机逻辑中,这不是查看的正确位置。

通过执行器端点公开的事件消费者缓冲区/actuator/circuitbreakerevents 将列出断路器中的所有事件、错误是什么以及相应的消息。

https://resilience4j.readme.io/docs/getting-started-3#events-endpoint