Skip to content

Commit

Permalink
CAMEL-21273: camel-jbang - Detect saga dsl (#15714)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhfeng committed Sep 26, 2024
1 parent d6d40c0 commit c4f2981
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
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;
Expand Down Expand Up @@ -468,6 +469,9 @@ protected CamelContext createCamelContext() {
// 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});
}
}

0 comments on commit c4f2981

Please sign in to comment.