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 9b9ad3d  Saga EIP: Add option to configure a specific saga service by 
reference id for XML DSL
9b9ad3d is described below

commit 9b9ad3d8e08b0a48a2a6a57c1067a1455bd3cf02
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Dec 28 20:17:40 2019 +0100

    Saga EIP: Add option to configure a specific saga service by reference id 
for XML DSL
---
 .../camel/spring/processor/SpringSagaRefTest.java  | 29 +++++++++++
 .../org/apache/camel/spring/processor/sagaRef.xml  | 56 ++++++++++++++++++++++
 .../src/main/docs/eips/saga-eip.adoc               |  1 +
 .../org/apache/camel/model/SagaDefinition.java     | 20 +++++++-
 .../java/org/apache/camel/reifier/SagaReifier.java |  4 ++
 5 files changed, 109 insertions(+), 1 deletion(-)

diff --git 
a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSagaRefTest.java
 
b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSagaRefTest.java
new file mode 100644
index 0000000..4511802
--- /dev/null
+++ 
b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSagaRefTest.java
@@ -0,0 +1,29 @@
+/*
+ * 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.spring.processor;
+
+import org.apache.camel.CamelContext;
+
+import static 
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringSagaRefTest extends SpringSagaTest {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        return createSpringCamelContext(this, 
"org/apache/camel/spring/processor/sagaRef.xml");
+    }
+}
diff --git 
a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/sagaRef.xml
 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/sagaRef.xml
new file mode 100644
index 0000000..b0eca72
--- /dev/null
+++ 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/sagaRef.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+    <bean id="mySagaService" 
class="org.apache.camel.impl.saga.InMemorySagaService" init-method="start"
+          destroy-method="stop"/>
+
+    <!-- START SNIPPET: example -->
+    <camelContext xmlns="http://camel.apache.org/schema/spring";>
+        <route>
+            <from uri="direct:start"/>
+            <saga sagaServiceRef="mySagaService">
+                <compensation uri="mock:compensation"/>
+                <completion uri="mock:completion"/>
+                <option optionName="myOptionKey">
+                    <constant>myOptionValue</constant>
+                </option>
+                <option optionName="myOptionKey2">
+                    <constant>myOptionValue2</constant>
+                </option>
+            </saga>
+            <choice>
+                <when>
+                    <simple>${body} == 'fail'</simple>
+                    <throwException exceptionType="java.lang.RuntimeException" 
message="fail"/>
+                </when>
+            </choice>
+            <to uri="mock:end"/>
+        </route>
+
+    </camelContext>
+    <!-- END SNIPPET: example -->
+
+</beans>
diff --git a/core/camel-core-engine/src/main/docs/eips/saga-eip.adoc 
b/core/camel-core-engine/src/main/docs/eips/saga-eip.adoc
index a867c89..86f1df3 100644
--- a/core/camel-core-engine/src/main/docs/eips/saga-eip.adoc
+++ b/core/camel-core-engine/src/main/docs/eips/saga-eip.adoc
@@ -32,6 +32,7 @@ The Saga EIP supports 6 options which are listed below:
 | *compensation* | The compensation endpoint URI that must be called to 
compensate all changes done in the route. The route corresponding to the 
compensation URI must perform compensation and complete without error. If 
errors occur during compensation, the saga service may call again the 
compensation URI to retry. |  | SagaActionUri Definition
 | *completion* | The completion endpoint URI that will be called when the Saga 
is completed successfully. The route corresponding to the completion URI must 
perform completion tasks and terminate without error. If errors occur during 
completion, the saga service may call again the completion URI to retry. |  | 
SagaActionUri Definition
 | *option* | Allows to save properties of the current exchange in order to 
re-use them in a compensation/completion callback route. Options are usually 
helpful e.g. to store and retrieve identifiers of objects that should be 
deleted in compensating actions. Option values will be transformed into input 
headers of the compensation/completion exchange. |  | List
+| *sagaServiceRef* |  Refers to the id to lookup in the registry for the 
specific CamelSagaService to use. | | String
 |===
 // eip options: END
 
diff --git 
a/core/camel-core-engine/src/main/java/org/apache/camel/model/SagaDefinition.java
 
b/core/camel-core-engine/src/main/java/org/apache/camel/model/SagaDefinition.java
index 1db4065..d0ba02d 100644
--- 
a/core/camel-core-engine/src/main/java/org/apache/camel/model/SagaDefinition.java
+++ 
b/core/camel-core-engine/src/main/java/org/apache/camel/model/SagaDefinition.java
@@ -60,8 +60,10 @@ public class SagaDefinition extends 
OutputDefinition<SagaDefinition> {
     @XmlElement(name = "option")
     private List<SagaOptionDefinition> options;
 
+    @XmlAttribute
+    private String sagaServiceRef;
     @XmlTransient
-    private CamelSagaService sagaService; // TODO add ref for xml configuration
+    private CamelSagaService sagaService;
 
     public SagaDefinition() {
     }
@@ -168,6 +170,17 @@ public class SagaDefinition extends 
OutputDefinition<SagaDefinition> {
         this.sagaService = sagaService;
     }
 
+    public String getSagaServiceRef() {
+        return sagaServiceRef;
+    }
+
+    /**
+     * Refers to the id to lookup in the registry for the specific 
CamelSagaService to use.
+     */
+    public void setSagaServiceRef(String sagaServiceRef) {
+        this.sagaServiceRef = sagaServiceRef;
+    }
+
     public List<SagaOptionDefinition> getOptions() {
         return options;
     }
@@ -231,6 +244,11 @@ public class SagaDefinition extends 
OutputDefinition<SagaDefinition> {
         return this;
     }
 
+    public SagaDefinition sagaServiceRef(String sagaServiceRef) {
+        setSagaServiceRef(sagaServiceRef);
+        return this;
+    }
+
     public SagaDefinition completionMode(SagaCompletionMode completionMode) {
         setCompletionMode(completionMode);
         return this;
diff --git 
a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/SagaReifier.java
 
b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/SagaReifier.java
index 45dcb71..6f4aa21 100644
--- 
a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/SagaReifier.java
+++ 
b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/SagaReifier.java
@@ -95,6 +95,10 @@ public class SagaReifier extends 
ProcessorReifier<SagaDefinition> {
             return sagaService;
         }
 
+        if (definition.getSagaServiceRef() != null) {
+            return CamelContextHelper.mandatoryLookup(context, 
definition.getSagaServiceRef(), CamelSagaService.class);
+        }
+
         sagaService = context.hasService(CamelSagaService.class);
         if (sagaService != null) {
             return sagaService;

Reply via email to