This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 637a381c31e CAMEL-18669: camel-jbang - Using resilience4j as CB should
include include dependency
637a381c31e is described below
commit 637a381c31eab546627ddb7f44d5a570ad691f8e
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Oct 31 13:28:24 2022 +0100
CAMEL-18669: camel-jbang - Using resilience4j as CB should include include
dependency
---
.../java/org/apache/camel/main/KameletMain.java | 4 ++
.../main/download/CircuitBreakerDownloader.java | 75 ++++++++++++++++++++++
2 files changed, 79 insertions(+)
diff --git
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
index 1c200e4c90f..29425efe780 100644
---
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
+++
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
@@ -27,6 +27,7 @@ import org.apache.camel.ProducerTemplate;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.main.download.AutoConfigureDownloadListener;
+import org.apache.camel.main.download.CircuitBreakerDownloader;
import org.apache.camel.main.download.CommandLineDependencyDownloader;
import org.apache.camel.main.download.DependencyDownloaderClassLoader;
import org.apache.camel.main.download.DependencyDownloaderClassResolver;
@@ -325,6 +326,9 @@ public class KameletMain extends MainCommandLineSupport {
} catch (Exception e) {
throw RuntimeCamelException.wrapRuntimeException(e);
}
+
+ // in case we use circuit breakers
+ CircuitBreakerDownloader.registerDownloadReifiers();
}
if (stub) {
// turn off auto-wiring when running in stub mode
diff --git
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/CircuitBreakerDownloader.java
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/CircuitBreakerDownloader.java
new file mode 100644
index 00000000000..0b4f367864f
--- /dev/null
+++
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/CircuitBreakerDownloader.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.main.download;
+
+import java.util.function.BiFunction;
+
+import org.apache.camel.Route;
+import org.apache.camel.model.CircuitBreakerDefinition;
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.reifier.ProcessReifier;
+import org.apache.camel.reifier.ProcessorReifier;
+
+/**
+ * When using circuit breakers then we need to download the runtime
implementation
+ */
+public class CircuitBreakerDownloader {
+
+ public static void registerDownloadReifiers() {
+ ProcessorReifier.registerReifier(CircuitBreakerDefinition.class,
+ new BiFunction<Route, ProcessorDefinition<?>,
ProcessorReifier<? extends ProcessorDefinition<?>>>() {
+ @Override
+ public ProcessorReifier<? extends ProcessorDefinition<?>>
apply(
+ Route route, ProcessorDefinition<?>
processorDefinition) {
+ if (processorDefinition instanceof
CircuitBreakerDefinition) {
+ CircuitBreakerDefinition cb =
(CircuitBreakerDefinition) processorDefinition;
+ DependencyDownloader downloader =
route.getCamelContext().hasService(DependencyDownloader.class);
+ if (downloader != null) {
+ String artifactId = null;
+ if (cb.getResilience4jConfiguration() != null)
{
+
downloader.downloadDependency("org.apache.camel", "camel-resilience4j",
+
route.getCamelContext().getVersion());
+ }
+ if (cb.getFaultToleranceConfiguration() !=
null) {
+
downloader.downloadDependency("org.apache.camel",
"camel-microprofile-fault-tolerance",
+
route.getCamelContext().getVersion());
+ }
+ if (cb.getConfiguration() != null) {
+ String id = cb.getConfiguration();
+ Object cfg =
route.getCamelContext().adapt(ModelCamelContext.class)
+ .getResilience4jConfiguration(id);
+ if (cfg != null) {
+
downloader.downloadDependency("org.apache.camel", "camel-resilience4j",
+
route.getCamelContext().getVersion());
+ }
+ cfg =
route.getCamelContext().adapt(ModelCamelContext.class)
+
.getFaultToleranceConfiguration(id);
+ if (cfg != null) {
+
downloader.downloadDependency("org.apache.camel",
"camel-microprofile-fault-tolerance",
+
route.getCamelContext().getVersion());
+ }
+ }
+ }
+ }
+ // use core reifier now we have downloaded JARs if
needed
+ return ProcessReifier.coreReifier(route,
processorDefinition);
+ }
+ });
+ }
+
+}