0

我们在路由中添加了断路器(resilience4j),带有 inheritErrorHandler(true)(见下文)

<?xml version="1.0" encoding="UTF-8"?>
<route xmlns="http://camel.apache.org/schema/spring" id="asyncOneConsumer.out" streamCache="true">
   <from uri="kafka:asyncOneConsumer?brokers=localhost:9092&amp;headerDeserializer=#stringKafkaHeaderDeserializer" />
   <onException>
      <exception>java.lang.Exception</exception>
      <redeliveryPolicy logExhausted="false" logExhaustedMessageHistory="false" logStackTrace="false" />
      <bean />
   </onException>
   <log loggingLevel="DEBUG" message="Consumed: ${body} for route asyncOneConsumer.out" />
   <process />
   <setHeader name="LOGGING_TYPE">
      <constant>OUTBOUND_REQUEST</constant>
   </setHeader>
   <process />
   <process />
   <removeHeaders pattern="CamelHttp*" />
   <removeHeader headerName="CamelServletContextPath" />
   <setHeader name="CamelHttpMethod">
      <expressionDefinition>org.apache.camel.model.ProcessorDefinition$2@61fd6c7b</expressionDefinition>
   </setHeader>
   <setHeader name="Content-Type">
      <expressionDefinition>org.apache.camel.model.ProcessorDefinition$2@1fe0295a</expressionDefinition>
   </setHeader>
   <process />
   <process />
   <circuitBreaker inheritErrorHandler="true">
      <resilience4jConfiguration failureRateThreshold="50.0" minimumNumberOfCalls="3" permittedNumberOfCallsInHalfOpenState="10" slidingWindowSize="10" slowCallDurationThreshold="60" slowCallRateThreshold="100.0" waitDurationInOpenState="10">
         <timeoutEnabled>true</timeoutEnabled>
         <timeoutDuration>30000</timeoutDuration>
      </resilience4jConfiguration>
      <process />
      <setHeader name="LOGGING_TYPE">
         <constant>OUTBOUND_RESPONSE</constant>
      </setHeader>
      <process />
   </circuitBreaker>
</route>

我们希望当 CB 打开时,日志中不会显示任何堆栈跟踪,但是会打印出来:

2021-03-16 16:42:44,675 | WARN  | [sumer[asyncOneConsumer]] | o.a.c.c.k.KafkaConsumer        | [           -           ] | Error during processing. Exchange[99D52C2E6F3A673-000000000000001B]. Caused by: [io.github.resilience4j.circuitbreaker.CallNotPermittedException - CircuitBreaker 'circuitBreaker1' is OPEN and does not permit further calls]
io.github.resilience4j.circuitbreaker.CallNotPermittedException: CircuitBreaker 'circuitBreaker1' is OPEN and does not permit further calls
    at io.github.resilience4j.circuitbreaker.CallNotPermittedException.createCallNotPermittedException(CallNotPermittedException.java:45)
    at io.github.resilience4j.circuitbreaker.internal.CircuitBreakerStateMachine$OpenState.acquirePermission(CircuitBreakerStateMachine.java:660)
    at io.github.resilience4j.circuitbreaker.internal.CircuitBreakerStateMachine.acquirePermission(CircuitBreakerStateMachine.java:190)
    at io.github.resilience4j.circuitbreaker.CircuitBreaker.lambda$decorateCallable$3(CircuitBreaker.java:169)
    at io.vavr.control.Try.of(Try.java:75)
    at io.vavr.control.Try.ofCallable(Try.java:105)
    at org.apache.camel.component.resilience4j.ResilienceProcessor.process(ResilienceProcessor.java:383)
    at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$RedeliveryTask.doRun(RedeliveryErrorHandler.java:714)
    at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$RedeliveryTask.run(RedeliveryErrorHandler.java:623)
    at org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:148)
    at org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:60)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:147)
    at org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInternalProcessor.java:312)
    at org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager.process(DefaultAsyncProcessorAwaitManager.java:83)
    at org.apache.camel.support.AsyncProcessorSupport.process(AsyncProcessorSupport.java:41)
    at org.apache.camel.component.kafka.KafkaConsumer$KafkaFetchRecords.doRun(KafkaConsumer.java:357)
    at org.apache.camel.component.kafka.KafkaConsumer$KafkaFetchRecords.run(KafkaConsumer.java:222)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)

在 3.7.0 中运行相同的示例时,不会打印堆栈跟踪。这是一个错误还是我们错误地使用了 onException 子句?

4

0 回答 0