Apache Camel 中的断路器使用 Quarkus

问题描述

我正在尝试使用 Quarkus(版本:1.12.0.Final)在 Apache camel(版本:3.8.0)中使用 CircuitBreaker 组件并包含以下依赖项。

<dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-microprofile-fault-tolerance</artifactId>
</dependency>

我的骆驼路线代码如下:

  //Some code above

  .circuitBreaker()              
    .faultToleranceConfiguration().timeoutEnabled(true).timeoutDuration(20000).end()
    .toD(nettyHttp("https://myurl"))
  .endCircuitBreaker()

  //Some code below;

我在编译时收到以下错误


Caused by: java.lang.IllegalStateException: Cannot find camel-hystrix,camel-resilience4j or camel-microprofile-fault-tolerance on the classpath.
    at org.apache.camel.reifier.CircuitBreakerReifier.createProcessor(CircuitBreakerReifier.java:32)
    at org.apache.camel.reifier.ProcessorReifier.makeProcessor(ProcessorReifier.java:835)
    at org.apache.camel.reifier.ProcessorReifier.addRoutes(ProcessorReifier.java:576)

我做错了什么,或者更确切地说是如何使用 Camel-Quarkus 合并 CircuitBreaker?

谢谢,

解决方法

我正在准备有关断路器和夸克的演示文稿。我也在使用 1.12.0.Final quarkus 版本。我没有遇到任何问题。我认为你的问题是 maven 。从您的计算机中删除 .m2 文件夹并再次运行。 ./mvnw compile quarkus:dev 如果问题仍然存在,请将此依赖项添加到您的 pom.xml

 <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-resilience4j</artifactId>
        <version>3.8.0</version>
    </dependency>

并像这样配置

 from("timer:circuitTimer?delay=1000&period=1000")
           .circuitBreaker()
           .resilience4jConfiguration()
           .timeoutEnabled(true)
           .timeoutDuration(2000)
           .minimumNumberOfCalls(3)
           .waitDurationInOpenState(10)
           .end()
           .to("http://localhost:8081/book/1000")
            .onFallback()
            .transform().constant("Camel In Action")
            .end().end().log("${body}");
,

这就是我使用 Camel-Quarkus 实现“微配置容错”的方式。 在 pom.xml 中包含 microprofile fault toterance 依赖

<dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-microprofile-fault-tolerance</artifactId>
</dependency>

使用您想要的值初始化以下类 FaultToleranceConfigurationDefinition

FaultToleranceConfigurationDefinition faultToleranceConfig = new FaultToleranceConfigurationDefinition();
         faultToleranceConfig
                .timeoutEnabled(true)
                .timeoutDuration(30000)
                .successThreshold(10)
                .requestVolumeThreshold(4)
                .delay(5000)
                .failureRatio(50)
                .bulkheadEnabled(true)
                .bulkheadMaxConcurrentCalls(5)
                .bulkheadWaitingTaskQueue(8)
                .end();

       

如何初始化 FaultToleranceConfigurationDefinition 类的实例取决于您(我们可以将其作为 Singleton 类),然后使用该类的实例,如下所示。

   
//Some code above

  .circuitBreaker()              
    .faultToleranceConfiguration(faultToleranceConfig)
    .toD(nettyHttp("https://myurl"))
  .endCircuitBreaker()

  //Some code below;

如果有更好的方法,请告诉我!! 谢谢