Reputation: 65
I am trying to use the CircuitBreaker component in Apache camel (version: 3.8.0) using Quarkus (version: 1.12.0.Final) and have included the following dependency.
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-microprofile-fault-tolerance</artifactId>
</dependency>
My camel route code is as follows:
//Some code above
.circuitBreaker()
.faultToleranceConfiguration().timeoutEnabled(true).timeoutDuration(20000).end()
.toD(nettyHttp("https://myurl"))
.endCircuitBreaker()
//Some code below;
I am getting the following error at compile time
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)
What am I doing wrong or rather how to incorporate CircuitBreaker using Camel-Quarkus?
Thanks,
Upvotes: 0
Views: 1596
Reputation: 65
This is how I made the "microprofile-fault-tolerance" work with Camel-Quarkus. Include the microprofile fault toterance dependency in pom.xml
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-microprofile-fault-tolerance</artifactId>
</dependency>
Initialize the following class FaultToleranceConfigurationDefinition with your desired value.
FaultToleranceConfigurationDefinition faultToleranceConfig = new FaultToleranceConfigurationDefinition();
faultToleranceConfig
.timeoutEnabled(true)
.timeoutDuration(30000)
.successThreshold(10)
.requestVolumeThreshold(4)
.delay(5000)
.failureRatio(50)
.bulkheadEnabled(true)
.bulkheadMaxConcurrentCalls(5)
.bulkheadWaitingTaskQueue(8)
.end();
How you initialize the instance of FaultToleranceConfigurationDefinition class is up to you (we can have it as Singleton class), then use the instance of the class as shown below.
//Some code above
.circuitBreaker()
.faultToleranceConfiguration(faultToleranceConfig)
.toD(nettyHttp("https://myurl"))
.endCircuitBreaker()
//Some code below;
If there is a better way, please let me know!! Thanks
Upvotes: 0
Reputation: 836
I am preparing a presentation for circuit breaker and quarkus. I'm working with the 1.12.0.Final quarkus version too. I did not come across any problem. ı think your problem is maven . remove .m2 folder from your computer and run again .
./mvnw compile quarkus:dev
if problem continues add this dependencies to your pom.xml
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-resilience4j</artifactId>
<version>3.8.0</version>
</dependency>
and configure it like that
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}");
Upvotes: 0