You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zh...@apache.org on 2024/09/26 13:22:13 UTC

(camel) branch camel-4.8.x updated: CAMEL-21273: camel-jbang - Detect saga dsl (#15714)

This is an automated email from the ASF dual-hosted git repository.

zhfeng pushed a commit to branch camel-4.8.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.8.x by this push:
     new c4f2981a940 CAMEL-21273: camel-jbang - Detect saga dsl (#15714)
c4f2981a940 is described below

commit c4f2981a9402b8fea0f56482a82c52d7445bcfb9
Author: Zheng Feng <zh...@gmail.com>
AuthorDate: Thu Sep 26 21:20:59 2024 +0800

    CAMEL-21273: camel-jbang - Detect saga dsl (#15714)
---
 .../java/org/apache/camel/main/KameletMain.java    |  4 ++
 .../apache/camel/main/download/SagaDownloader.java | 50 ++++++++++++++++++++++
 2 files changed, 54 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 94d714ca5c4..f7ed06aa653 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
@@ -67,6 +67,7 @@ import org.apache.camel.main.download.KnownReposResolver;
 import org.apache.camel.main.download.MavenDependencyDownloader;
 import org.apache.camel.main.download.PackageNameSourceLoader;
 import org.apache.camel.main.download.PromptPropertyPlaceholderSource;
+import org.apache.camel.main.download.SagaDownloader;
 import org.apache.camel.main.download.StubBeanRepository;
 import org.apache.camel.main.download.TransactedDownloader;
 import org.apache.camel.main.download.TypeConverterLoaderDownloadListener;
@@ -468,6 +469,9 @@ public class KameletMain extends MainCommandLineSupport {
         // in case we use transacted
         TransactedDownloader.registerDownloadReifiers(this);
 
+        // in case we use saga
+        SagaDownloader.registerDownloadReifiers(this);
+
         if (silent || "*".equals(stubPattern)) {
             // turn off auto-wiring when running in silent mode (or stub = *)
             mainConfigurationProperties.setAutowiredEnabled(false);
diff --git a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/SagaDownloader.java b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/SagaDownloader.java
new file mode 100644
index 00000000000..9473adf0d39
--- /dev/null
+++ b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/SagaDownloader.java
@@ -0,0 +1,50 @@
+/*
+ * 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 org.apache.camel.main.KameletMain;
+import org.apache.camel.model.SagaDefinition;
+import org.apache.camel.reifier.ProcessReifier;
+import org.apache.camel.reifier.ProcessorReifier;
+import org.apache.camel.saga.InMemorySagaService;
+
+/**
+ * When using saga then we need to register a CamelSagaService
+ */
+public class SagaDownloader {
+
+    private SagaDownloader() {
+    }
+
+    public static void registerDownloadReifiers(KameletMain main) {
+
+        ProcessorReifier.registerReifier(SagaDefinition.class,
+                (route, processorDefinition) -> {
+                    if (processorDefinition instanceof SagaDefinition) {
+                        DependencyDownloader downloader = route.getCamelContext().hasService(DependencyDownloader.class);
+                        if (downloader != null) {
+                            downloader.downloadDependency("org.apache.camel", "camel-saga",
+                                    route.getCamelContext().getVersion());
+                            downloader.downloadDependency("org.apache.camel", "camel-lra",
+                                    route.getCamelContext().getVersion());
+                        }
+                    }
+                    main.bind("inMemorySagaService", new InMemorySagaService());
+                    return ProcessReifier.coreReifier(route, processorDefinition);
+                });
+    }
+}