This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new a8bfdf2 CAMEL-15164: camel-lra - Autodiscover when using camel-main
and allow to configure it via properties.
a8bfdf2 is described below
commit a8bfdf2dee4f7e793a37f13cd0d4e6bb90767552
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Jun 11 11:59:47 2020 +0200
CAMEL-15164: camel-lra - Autodiscover when using camel-main and allow to
configure it via properties.
---
components/camel-lra/pom.xml | 27 +++++++
.../service/lra/LRASagaServiceConfigurer.java | 65 ++++++++++++++++
.../org/apache/camel/configurer/LRASagaService | 2 +
.../services/org/apache/camel/lra-saga-service | 2 +
.../camel-lra/src/generated/resources/lra.json | 2 +-
components/camel-lra/src/main/docs/lra.adoc | 4 +-
.../org/apache/camel/service/lra/LRAClient.java | 3 -
.../apache/camel/service/lra/LRASagaService.java | 38 ++++++---
.../main/LraConfigurationPropertiesConfigurer.java | 60 +++++++++++++++
.../camel-main-configuration-metadata.json | 4 +
.../camel/configurer/LraConfigurationProperties | 2 +
.../org/apache/camel/main/BaseMainSupport.java | 49 +++++++++++-
.../camel/main/LraConfigurationProperties.java | 89 ++++++++++++++++++++++
.../camel/main/MainConfigurationProperties.java | 8 ++
14 files changed, 336 insertions(+), 19 deletions(-)
diff --git a/components/camel-lra/pom.xml b/components/camel-lra/pom.xml
index 34ff060..e891bc3 100644
--- a/components/camel-lra/pom.xml
+++ b/components/camel-lra/pom.xml
@@ -35,6 +35,7 @@
<!-- used by camel-catalog -->
<firstVersion>2.21.0</firstVersion>
<title>LRA</title>
+ <supportLevel>preview</supportLevel>
</properties>
<dependencies>
@@ -88,6 +89,32 @@
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <!-- we need to generate additional configurer classes from
camel-lra -->
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-package-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-configurer</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>generate-configurer</goal>
+ </goals>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-support</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
+
<profiles>
<profile>
<id>lra-integration-tests</id>
diff --git
a/components/camel-lra/src/generated/java/org/apache/camel/service/lra/LRASagaServiceConfigurer.java
b/components/camel-lra/src/generated/java/org/apache/camel/service/lra/LRASagaServiceConfigurer.java
new file mode 100644
index 0000000..9fd4981
--- /dev/null
+++
b/components/camel-lra/src/generated/java/org/apache/camel/service/lra/LRASagaServiceConfigurer.java
@@ -0,0 +1,65 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.service.lra;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.GeneratedPropertyConfigurer;
+import org.apache.camel.spi.PropertyConfigurerGetter;
+import org.apache.camel.util.CaseInsensitiveMap;
+import org.apache.camel.service.lra.LRASagaService;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+public class LRASagaServiceConfigurer extends
org.apache.camel.support.component.PropertyConfigurerSupport implements
GeneratedPropertyConfigurer, PropertyConfigurerGetter {
+
+ @Override
+ public boolean configure(CamelContext camelContext, Object obj, String
name, Object value, boolean ignoreCase) {
+ org.apache.camel.service.lra.LRASagaService target =
(org.apache.camel.service.lra.LRASagaService) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "camelcontext":
+ case "CamelContext": target.setCamelContext(property(camelContext,
org.apache.camel.CamelContext.class, value)); return true;
+ case "coordinatorcontextpath":
+ case "CoordinatorContextPath":
target.setCoordinatorContextPath(property(camelContext, java.lang.String.class,
value)); return true;
+ case "coordinatorurl":
+ case "CoordinatorUrl": target.setCoordinatorUrl(property(camelContext,
java.lang.String.class, value)); return true;
+ case "localparticipantcontextpath":
+ case "LocalParticipantContextPath":
target.setLocalParticipantContextPath(property(camelContext,
java.lang.String.class, value)); return true;
+ case "localparticipanturl":
+ case "LocalParticipantUrl":
target.setLocalParticipantUrl(property(camelContext, java.lang.String.class,
value)); return true;
+ default: return false;
+ }
+ }
+
+ @Override
+ public Map<String, Object> getAllOptions(Object target) {
+ Map<String, Object> answer = new CaseInsensitiveMap();
+ answer.put("CamelContext", org.apache.camel.CamelContext.class);
+ answer.put("CoordinatorContextPath", java.lang.String.class);
+ answer.put("CoordinatorUrl", java.lang.String.class);
+ answer.put("LocalParticipantContextPath", java.lang.String.class);
+ answer.put("LocalParticipantUrl", java.lang.String.class);
+ return answer;
+ }
+
+ @Override
+ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
+ org.apache.camel.service.lra.LRASagaService target =
(org.apache.camel.service.lra.LRASagaService) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "camelcontext":
+ case "CamelContext": return target.getCamelContext();
+ case "coordinatorcontextpath":
+ case "CoordinatorContextPath": return
target.getCoordinatorContextPath();
+ case "coordinatorurl":
+ case "CoordinatorUrl": return target.getCoordinatorUrl();
+ case "localparticipantcontextpath":
+ case "LocalParticipantContextPath": return
target.getLocalParticipantContextPath();
+ case "localparticipanturl":
+ case "LocalParticipantUrl": return target.getLocalParticipantUrl();
+ default: return null;
+ }
+ }
+}
+
diff --git
a/components/camel-lra/src/generated/resources/META-INF/services/org/apache/camel/configurer/LRASagaService
b/components/camel-lra/src/generated/resources/META-INF/services/org/apache/camel/configurer/LRASagaService
new file mode 100644
index 0000000..496ed2f
--- /dev/null
+++
b/components/camel-lra/src/generated/resources/META-INF/services/org/apache/camel/configurer/LRASagaService
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.service.lra.LRASagaServiceConfigurer
diff --git
a/components/camel-lra/src/generated/resources/META-INF/services/org/apache/camel/lra-saga-service
b/components/camel-lra/src/generated/resources/META-INF/services/org/apache/camel/lra-saga-service
new file mode 100644
index 0000000..06f2cf1
--- /dev/null
+++
b/components/camel-lra/src/generated/resources/META-INF/services/org/apache/camel/lra-saga-service
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.service.lra.LRASagaService
diff --git a/components/camel-lra/src/generated/resources/lra.json
b/components/camel-lra/src/generated/resources/lra.json
index 2424cb0..7dfe6a3 100644
--- a/components/camel-lra/src/generated/resources/lra.json
+++ b/components/camel-lra/src/generated/resources/lra.json
@@ -6,7 +6,7 @@
"description": "Camel saga binding for Long-Running-Action framework",
"deprecated": false,
"firstVersion": "2.21.0",
- "supportLevel": "Stable",
+ "supportLevel": "Preview",
"groupId": "org.apache.camel",
"artifactId": "camel-lra",
"version": "3.4.0-SNAPSHOT"
diff --git a/components/camel-lra/src/main/docs/lra.adoc
b/components/camel-lra/src/main/docs/lra.adoc
index 5e24bc5..1acc462 100644
--- a/components/camel-lra/src/main/docs/lra.adoc
+++ b/components/camel-lra/src/main/docs/lra.adoc
@@ -4,11 +4,11 @@
:artifactId: camel-lra
:description: Camel saga binding for Long-Running-Action framework
:since: 2.21
-:supportLevel: Stable
+:supportLevel: Preview
*Since Camel {since}*
-The LRA module provides bindings of the Saga EIP with any
https://github.com/eclipse/microprofile-sandbox/tree/master/proposals/0009-LRA[MicroProfile
compatible LRA Coordinator (sandbox)].
+The LRA module provides bindings of the Saga EIP with any
https://github.com/eclipse/microprofile-lra[MicroProfile compatible LRA
Coordinator].
Maven users will need to add the following dependency to their `pom.xml`
for this component:
diff --git
a/components/camel-lra/src/main/java/org/apache/camel/service/lra/LRAClient.java
b/components/camel-lra/src/main/java/org/apache/camel/service/lra/LRAClient.java
index cbcaf84..9cf9dce 100644
---
a/components/camel-lra/src/main/java/org/apache/camel/service/lra/LRAClient.java
+++
b/components/camel-lra/src/main/java/org/apache/camel/service/lra/LRAClient.java
@@ -43,11 +43,8 @@ import static
org.apache.camel.service.lra.LRAConstants.PARTICIPANT_PATH_COMPLET
public class LRAClient implements Closeable {
-
private final LRASagaService sagaService;
-
private final Client client;
-
private final WebTarget target;
public LRAClient(LRASagaService sagaService) {
diff --git
a/components/camel-lra/src/main/java/org/apache/camel/service/lra/LRASagaService.java
b/components/camel-lra/src/main/java/org/apache/camel/service/lra/LRASagaService.java
index e5f47ab..de6870f 100644
---
a/components/camel-lra/src/main/java/org/apache/camel/service/lra/LRASagaService.java
+++
b/components/camel-lra/src/main/java/org/apache/camel/service/lra/LRASagaService.java
@@ -25,35 +25,41 @@ import java.util.concurrent.ScheduledExecutorService;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.StaticService;
+import org.apache.camel.api.management.ManagedAttribute;
+import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.saga.CamelSagaCoordinator;
import org.apache.camel.saga.CamelSagaService;
import org.apache.camel.saga.CamelSagaStep;
+import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.annotations.JdkService;
import org.apache.camel.support.service.ServiceSupport;
/**
- * A Camel saga service based on LRA
(https://github.com/eclipse/microprofile-sandbox/tree/master/proposals/0009-LRA).
+ * A Camel saga service based on Microprofile LRA
(https://github.com/eclipse/microprofile-lra).
*/
-public class LRASagaService extends ServiceSupport implements CamelSagaService
{
+@JdkService("lra-saga-service")
+@Configurer
+@ManagedResource(description = "Managed LRASagaService")
+public class LRASagaService extends ServiceSupport implements StaticService,
CamelSagaService {
private CamelContext camelContext;
-
private ScheduledExecutorService executorService;
-
private LRAClient client;
-
private LRASagaRoutes routes;
+ private final Set<String> sagaURIs = ConcurrentHashMap.newKeySet();
+ // we want to be able to configure these following options
+ @Metadata
private String coordinatorUrl;
-
+ @Metadata
private String coordinatorContextPath =
LRAConstants.DEFAULT_COORDINATOR_CONTEXT_PATH;
-
+ @Metadata
private String localParticipantUrl;
-
+ @Metadata
private String localParticipantContextPath =
LRAConstants.DEFAULT_LOCAL_PARTICIPANT_CONTEXT_PATH;
- private Set<String> sagaURIs = ConcurrentHashMap.newKeySet();
-
-
public LRASagaService() {
}
@@ -112,7 +118,7 @@ public class LRASagaService extends ServiceSupport
implements CamelSagaService {
try {
this.camelContext.addRoutes(this.routes);
} catch (Exception ex) {
- throw new RuntimeCamelException(ex);
+ throw RuntimeCamelException.wrapRuntimeException(ex);
}
}
}
@@ -130,6 +136,7 @@ public class LRASagaService extends ServiceSupport
implements CamelSagaService {
return client;
}
+ @ManagedAttribute(description = "Coordinator URL")
public String getCoordinatorUrl() {
return coordinatorUrl;
}
@@ -138,6 +145,7 @@ public class LRASagaService extends ServiceSupport
implements CamelSagaService {
this.coordinatorUrl = coordinatorUrl;
}
+ @ManagedAttribute(description = "Coordinator context-path")
public String getCoordinatorContextPath() {
return coordinatorContextPath;
}
@@ -146,6 +154,7 @@ public class LRASagaService extends ServiceSupport
implements CamelSagaService {
this.coordinatorContextPath = coordinatorContextPath;
}
+ @ManagedAttribute(description = "Local participant URL")
public String getLocalParticipantUrl() {
return localParticipantUrl;
}
@@ -154,6 +163,7 @@ public class LRASagaService extends ServiceSupport
implements CamelSagaService {
this.localParticipantUrl = localParticipantUrl;
}
+ @ManagedAttribute(description = "Local participant context-path")
public String getLocalParticipantContextPath() {
return localParticipantContextPath;
}
@@ -166,4 +176,8 @@ public class LRASagaService extends ServiceSupport
implements CamelSagaService {
return sagaURIs;
}
+ @Override
+ public String toString() {
+ return "lra-saga-service";
+ }
}
diff --git
a/core/camel-main/src/generated/java/org/apache/camel/main/LraConfigurationPropertiesConfigurer.java
b/core/camel-main/src/generated/java/org/apache/camel/main/LraConfigurationPropertiesConfigurer.java
new file mode 100644
index 0000000..700c5d7
--- /dev/null
+++
b/core/camel-main/src/generated/java/org/apache/camel/main/LraConfigurationPropertiesConfigurer.java
@@ -0,0 +1,60 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.main;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.GeneratedPropertyConfigurer;
+import org.apache.camel.spi.PropertyConfigurerGetter;
+import org.apache.camel.util.CaseInsensitiveMap;
+import org.apache.camel.main.LraConfigurationProperties;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+public class LraConfigurationPropertiesConfigurer extends
org.apache.camel.support.component.PropertyConfigurerSupport implements
GeneratedPropertyConfigurer, PropertyConfigurerGetter {
+
+ @Override
+ public boolean configure(CamelContext camelContext, Object obj, String
name, Object value, boolean ignoreCase) {
+ org.apache.camel.main.LraConfigurationProperties target =
(org.apache.camel.main.LraConfigurationProperties) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "coordinatorcontextpath":
+ case "CoordinatorContextPath":
target.setCoordinatorContextPath(property(camelContext, java.lang.String.class,
value)); return true;
+ case "coordinatorurl":
+ case "CoordinatorUrl": target.setCoordinatorUrl(property(camelContext,
java.lang.String.class, value)); return true;
+ case "localparticipantcontextpath":
+ case "LocalParticipantContextPath":
target.setLocalParticipantContextPath(property(camelContext,
java.lang.String.class, value)); return true;
+ case "localparticipanturl":
+ case "LocalParticipantUrl":
target.setLocalParticipantUrl(property(camelContext, java.lang.String.class,
value)); return true;
+ default: return false;
+ }
+ }
+
+ @Override
+ public Map<String, Object> getAllOptions(Object target) {
+ Map<String, Object> answer = new CaseInsensitiveMap();
+ answer.put("CoordinatorContextPath", java.lang.String.class);
+ answer.put("CoordinatorUrl", java.lang.String.class);
+ answer.put("LocalParticipantContextPath", java.lang.String.class);
+ answer.put("LocalParticipantUrl", java.lang.String.class);
+ return answer;
+ }
+
+ @Override
+ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
+ org.apache.camel.main.LraConfigurationProperties target =
(org.apache.camel.main.LraConfigurationProperties) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "coordinatorcontextpath":
+ case "CoordinatorContextPath": return
target.getCoordinatorContextPath();
+ case "coordinatorurl":
+ case "CoordinatorUrl": return target.getCoordinatorUrl();
+ case "localparticipantcontextpath":
+ case "LocalParticipantContextPath": return
target.getLocalParticipantContextPath();
+ case "localparticipanturl":
+ case "LocalParticipantUrl": return target.getLocalParticipantUrl();
+ default: return null;
+ }
+ }
+}
+
diff --git
a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
index 6e11290..87df318 100644
---
a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
+++
b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
@@ -26,6 +26,8 @@
{ "name": "camel.main.configurations", "description": "Sets the
configuration objects used to configure the camel context.", "sourceType":
"org.apache.camel.main.MainConfigurationProperties", "type": "object",
"javaType": "java.util.List", "defaultValue": "new ArrayList<>()" },
{ "name": "camel.main.consumerTemplateCacheSize", "description": "Consumer
template endpoints cache size.", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "integer",
"javaType": "int", "defaultValue": 1000 },
{ "name": "camel.main.contextEnabled", "description": "Whether context
health check is enabled Is default enabled", "sourceType":
"org.apache.camel.main.HealthConfigurationProperties", "type": "boolean",
"javaType": "java.lang.Boolean" },
+ { "name": "camel.main.coordinatorContextPath", "description": "The
context-path for the LRA coordinator. Is default \/lra-coordinator",
"sourceType": "org.apache.camel.main.LraConfigurationProperties", "type":
"string", "javaType": "java.lang.String", "defaultValue": "\/lra-coordinator" },
+ { "name": "camel.main.coordinatorUrl", "description": "The URL for the LRA
coordinator service that orchestrates the transactions", "sourceType":
"org.apache.camel.main.LraConfigurationProperties", "type": "string",
"javaType": "java.lang.String" },
{ "name": "camel.main.durationHitExitCode", "description": "Sets the exit
code for the application if duration was hit", "sourceType":
"org.apache.camel.main.MainConfigurationProperties", "type": "integer",
"javaType": "int" },
{ "name": "camel.main.durationMaxIdleSeconds", "description": "To specify
for how long time in seconds Camel can be idle before automatic terminating the
JVM. You can use this to run Camel for a short while.", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "integer",
"javaType": "int" },
{ "name": "camel.main.durationMaxMessages", "description": "To specify how
many messages to process by Camel before automatic terminating the JVM. You can
use this to run Camel for a short while.", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "integer",
"javaType": "int" },
@@ -44,6 +46,8 @@
{ "name": "camel.main.jmxManagementStatisticsLevel", "description": "Sets
the JMX statistics level The level can be set to Extended to gather additional
information The default value is Default.", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "object",
"javaType": "org.apache.camel.ManagementStatisticsLevel", "defaultValue":
"ManagementStatisticsLevel.Default", "enum": [ "Extended", "Default",
"RoutesOnly", "Off" ] },
{ "name": "camel.main.lightweight", "description": "Experimental:
Configure the context to be lightweight. This will trigger some optimizations
and memory reduction options. Lightweight context have some limitations. At
this moment, dynamic endpoint destinations are not supported.", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean",
"javaType": "boolean" },
{ "name": "camel.main.loadTypeConverters", "description": "Whether to load
custom type converters by scanning classpath. This is used for backwards
compatibility with Camel 2.x. Its recommended to migrate to use fast type
converter loading by setting Converter(loader = true) on your custom type
converter classes.", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean",
"javaType": "boolean" },
+ { "name": "camel.main.localParticipantContextPath", "description": "The
context-path for the local participant. Is default \/lra-participant",
"sourceType": "org.apache.camel.main.LraConfigurationProperties", "type":
"string", "javaType": "java.lang.String", "defaultValue": "\/lra-participant" },
+ { "name": "camel.main.localParticipantUrl", "description": "The URL for
the local participant", "sourceType":
"org.apache.camel.main.LraConfigurationProperties", "type": "string",
"javaType": "java.lang.String" },
{ "name": "camel.main.logDebugMaxChars", "description": "Is used to limit
the maximum length of the logging Camel message bodies. If the message body is
longer than the limit, the log message is clipped. Use -1 to have unlimited
length. Use for example 1000 to log at most 1000 characters.", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "integer",
"javaType": "int" },
{ "name": "camel.main.logExhaustedMessageBody", "description": "Sets
whether to log exhausted message body with message history. Default is false.",
"sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type":
"boolean", "javaType": "boolean" },
{ "name": "camel.main.logMask", "description": "Sets whether log mask is
enabled or not. Default is false.", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean",
"javaType": "boolean" },
diff --git
a/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/LraConfigurationProperties
b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/LraConfigurationProperties
new file mode 100644
index 0000000..4889fe0
--- /dev/null
+++
b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/LraConfigurationProperties
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.main.LraConfigurationPropertiesConfigurer
diff --git
a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 52f72cd..5a10a7c 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -54,6 +54,7 @@ import org.apache.camel.model.Model;
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.model.Resilience4jConfigurationDefinition;
import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.saga.CamelSagaService;
import org.apache.camel.spi.CamelBeanPostProcessor;
import org.apache.camel.spi.DataFormat;
import org.apache.camel.spi.ExecutorServiceManager;
@@ -688,6 +689,7 @@ public abstract class BaseMainSupport extends BaseService {
Map<String, Object> restProperties = new LinkedHashMap<>();
Map<String, Object> threadPoolProperties = new LinkedHashMap<>();
Map<String, Object> healthProperties = new LinkedHashMap<>();
+ Map<String, Object> lraProperties = new LinkedHashMap<>();
Map<String, Object> beansProperties = new LinkedHashMap<>();
for (String key : prop.stringPropertyNames()) {
if (key.startsWith("camel.context.")) {
@@ -732,6 +734,12 @@ public abstract class BaseMainSupport extends BaseService {
String option = key.substring(13);
validateOptionAndValue(key, option, value);
healthProperties.put(optionKey(option), value);
+ } else if (key.startsWith("camel.lra.")) {
+ // grab the value
+ String value = prop.getProperty(key);
+ String option = key.substring(10);
+ validateOptionAndValue(key, option, value);
+ lraProperties.put(optionKey(option), value);
} else if (key.startsWith("camel.beans.")) {
// grab the value
String value = prop.getProperty(key);
@@ -803,6 +811,10 @@ public abstract class BaseMainSupport extends BaseService {
LOG.debug("Auto-configuring HealthCheck from loaded properties:
{}", healthProperties.size());
setHealthCheckProperties(camelContext, healthProperties,
mainConfigurationProperties.isAutoConfigurationFailFast(),
autoConfiguredProperties);
}
+ if (!lraProperties.isEmpty()) {
+ LOG.debug("Auto-configuring Saga LRA from loaded properties: {}",
lraProperties.size());
+ setLraCheckProperties(camelContext, lraProperties,
mainConfigurationProperties.isAutoConfigurationFailFast(),
autoConfiguredProperties);
+ }
// log which options was not set
if (!beansProperties.isEmpty()) {
@@ -849,7 +861,12 @@ public abstract class BaseMainSupport extends BaseService {
}
if (!healthProperties.isEmpty()) {
healthProperties.forEach((k, v) -> {
- LOG.warn("Property not auto-configured: camel.health{}={}", k,
v);
+ LOG.warn("Property not auto-configured: camel.health.{}={}",
k, v);
+ });
+ }
+ if (!lraProperties.isEmpty()) {
+ lraProperties.forEach((k, v) -> {
+ LOG.warn("Property not auto-configured: camel.lra.{}={}", k,
v);
});
}
@@ -1027,6 +1044,36 @@ public abstract class BaseMainSupport extends
BaseService {
}
}
+ private void setLraCheckProperties(CamelContext camelContext, Map<String,
Object> lraProperties,
+ boolean failIfNotSet, Map<String,
String> autoConfiguredProperties) throws Exception {
+
+ Object obj = lraProperties.get("enabled");
+ if (obj != null) {
+ autoConfiguredProperties.put("camel.lra.enabled", obj.toString());
+ }
+ boolean enabled = obj != null ?
CamelContextHelper.parseBoolean(camelContext, obj.toString()) : true;
+ if (enabled) {
+ CamelSagaService css = resolveLraSagaService(camelContext);
+ setPropertiesOnTarget(camelContext, css, lraProperties,
"camel.lra.", failIfNotSet, true, autoConfiguredProperties);
+ }
+ }
+
+ private static CamelSagaService resolveLraSagaService(CamelContext
camelContext) throws Exception {
+ // lookup in service registry first
+ Set<CamelSagaService> set =
camelContext.getRegistry().findByType(CamelSagaService.class);
+ if (set.size() == 1) {
+ return set.iterator().next();
+ }
+ CamelSagaService answer =
camelContext.adapt(ExtendedCamelContext.class).getDefaultFactoryFinder()
+ .newInstance("lra-saga-service", CamelSagaService.class)
+ .orElseThrow(() -> new IllegalArgumentException("Cannot find
LRASagaService on classpath. "
+ + "Add camel-lra to classpath."));
+
+ // add as service so its discover by saga eip
+ camelContext.addService(answer, true, false);
+ return answer;
+ }
+
private void bindBeansToRegistry(CamelContext camelContext, Map<String,
Object> properties,
String optionPrefix, boolean
failIfNotSet, boolean ignoreCase,
Map<String, String>
autoConfiguredProperties) throws Exception {
diff --git
a/core/camel-main/src/main/java/org/apache/camel/main/LraConfigurationProperties.java
b/core/camel-main/src/main/java/org/apache/camel/main/LraConfigurationProperties.java
new file mode 100644
index 0000000..aa0184b
--- /dev/null
+++
b/core/camel-main/src/main/java/org/apache/camel/main/LraConfigurationProperties.java
@@ -0,0 +1,89 @@
+/*
+ * 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;
+
+import org.apache.camel.spi.Configurer;
+
+/**
+ * Global configuration for Saga LRA
+ */
+@Configurer
+public class LraConfigurationProperties {
+
+ private final MainConfigurationProperties parent;
+
+ private String coordinatorUrl;
+ private String coordinatorContextPath = "/lra-coordinator";
+ private String localParticipantUrl;
+ private String localParticipantContextPath = "/lra-participant";
+
+ public LraConfigurationProperties(MainConfigurationProperties parent) {
+ this.parent = parent;
+ }
+
+ public MainConfigurationProperties end() {
+ return parent;
+ }
+
+ public String getCoordinatorUrl() {
+ return coordinatorUrl;
+ }
+
+ /**
+ * The URL for the LRA coordinator service that orchestrates the
transactions
+ */
+ public void setCoordinatorUrl(String coordinatorUrl) {
+ this.coordinatorUrl = coordinatorUrl;
+ }
+
+ public String getCoordinatorContextPath() {
+ return coordinatorContextPath;
+ }
+
+ /**
+ * The context-path for the LRA coordinator.
+ *
+ * Is default /lra-coordinator
+ */
+ public void setCoordinatorContextPath(String coordinatorContextPath) {
+ this.coordinatorContextPath = coordinatorContextPath;
+ }
+
+ public String getLocalParticipantUrl() {
+ return localParticipantUrl;
+ }
+
+ /**
+ * The URL for the local participant
+ */
+ public void setLocalParticipantUrl(String localParticipantUrl) {
+ this.localParticipantUrl = localParticipantUrl;
+ }
+
+ public String getLocalParticipantContextPath() {
+ return localParticipantContextPath;
+ }
+
+ /**
+ * The context-path for the local participant.
+ *
+ * Is default /lra-participant
+ */
+ public void setLocalParticipantContextPath(String
localParticipantContextPath) {
+ this.localParticipantContextPath = localParticipantContextPath;
+ }
+}
diff --git
a/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java
b/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java
index 854be68..10e91c9 100644
---
a/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java
+++
b/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java
@@ -47,6 +47,7 @@ public class MainConfigurationProperties extends
DefaultConfigurationProperties<
// extended configuration
private final HealthConfigurationProperties healthConfigurationProperties
= new HealthConfigurationProperties(this);
+ private final LraConfigurationProperties lraConfigurationProperties = new
LraConfigurationProperties(this);
private final HystrixConfigurationProperties
hystrixConfigurationProperties = new HystrixConfigurationProperties(this);
private final Resilience4jConfigurationProperties
resilience4jConfigurationProperties = new
Resilience4jConfigurationProperties(this);
private final FaultToleranceConfigurationProperties
faultToleranceConfigurationProperties = new
FaultToleranceConfigurationProperties(this);
@@ -63,6 +64,13 @@ public class MainConfigurationProperties extends
DefaultConfigurationProperties<
}
/**
+ * To configure Saga LRA
+ */
+ public LraConfigurationProperties lra() {
+ return lraConfigurationProperties;
+ }
+
+ /**
* To configure Circuit Breaker EIP with Hystrix
*/
public HystrixConfigurationProperties hystrix() {