You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/04/15 12:36:59 UTC
[camel-k-runtime] 01/01: yaml dsl - Add idempotent consumer EIP and
update docs
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch eip
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git
commit ef2a9441db638f3ffc5ec099a24ff4c79e03a32a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Apr 15 14:36:40 2020 +0200
yaml dsl - Add idempotent consumer EIP and update docs
---
camel-k-loader-yaml/README.adoc | 33 ++++++++++---
.../yaml/parser/IdempotentConsumerParser.java | 46 ++++++++++++++++++
.../apache/camel/k/loader/yaml/RoutesTest.groovy | 31 ++++++++++++-
.../yaml/parser/IdempotentConsumerTest.groovy | 54 ++++++++++++++++++++++
.../routes/RoutesTest_idempotentConsumer.yaml | 25 ++++++++++
5 files changed, 181 insertions(+), 8 deletions(-)
diff --git a/camel-k-loader-yaml/README.adoc b/camel-k-loader-yaml/README.adoc
index 1ee9b30..90df923 100644
--- a/camel-k-loader-yaml/README.adoc
+++ b/camel-k-loader-yaml/README.adoc
@@ -1,14 +1,13 @@
-YAML DSL
-========
+= YAML DSL
This artifact provides a YAML based DSL for Apache Camel and Apache Camel K.
[WARNING]
====
-experimental
+Experimental
====
-=== Defining a route
+== Defining a route
A route is a sequence of elements, or `steps`, defined as follow:
@@ -116,31 +115,51 @@ In case you want to use the data-format's default settings, you need to place an
====
-=== Supported EIP
+== Supported EIP
+- Aggregate
+- Bean
- Choice
- Claim Check
- Convert Body
- Delay
+- Dynamic Router
+- Enrich
- Filter
+- From
+- Idempotent Consumer
- Log
+- Loop
- Marshal
+- Multicast
- Pipeline
+- PollEnrich
- Process
+- Recipient List
- Remove Header
- Remove Headers
- Remove Property
- Remove Properties
+- Resequence
+- Rest DSL
+- Routing Slip
+- Sample
- Set Body
- Set Header
- Set Property
+- Sort
- Split
+- Threads
+- Throttle
- To
- To Dynamic
- Transform
+- Unmarshal
+- Validate
+- Wire Tap
-=== Extending the DSL
+== Extending the DSL
The DSL is designed to be easily extended so you can provide your own step handler which is discovered at runtime using Camel's factory finder.
@@ -201,4 +220,4 @@ from:
host: acme.com
port: 8081
----
-<1> Parameters go here
+
diff --git a/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/IdempotentConsumerParser.java b/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/IdempotentConsumerParser.java
new file mode 100644
index 0000000..e35ba8d
--- /dev/null
+++ b/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/IdempotentConsumerParser.java
@@ -0,0 +1,46 @@
+/*
+ * 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.k.loader.yaml.parser;
+
+import java.util.List;
+
+import org.apache.camel.k.annotation.yaml.YAMLNodeDefinition;
+import org.apache.camel.k.annotation.yaml.YAMLStepParser;
+import org.apache.camel.k.loader.yaml.model.Step;
+import org.apache.camel.model.IdempotentConsumerDefinition;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.reifier.IdempotentConsumerReifier;
+
+@YAMLStepParser("idempotent-consumer")
+public class IdempotentConsumerParser implements ProcessorStepParser {
+ @Override
+ public ProcessorDefinition<?> toProcessor(Context context) {
+ Definition definition = context.node(Definition.class);
+
+ return StepParserSupport.convertSteps(
+ context,
+ definition,
+ definition.steps
+ );
+ }
+
+ @YAMLNodeDefinition(reifiers = IdempotentConsumerReifier.class)
+ public static final class Definition extends IdempotentConsumerDefinition implements HasExpression {
+ public List<Step> steps;
+ }
+}
+
diff --git a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/RoutesTest.groovy b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/RoutesTest.groovy
index db020e4..3fc24b0 100644
--- a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/RoutesTest.groovy
+++ b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/RoutesTest.groovy
@@ -16,9 +16,9 @@
*/
package org.apache.camel.k.loader.yaml
-
import org.apache.camel.component.mock.MockEndpoint
import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy
+import org.apache.camel.support.processor.idempotent.MemoryIdempotentRepository
class RoutesTest extends TestSupport {
@@ -100,4 +100,33 @@ class RoutesTest extends TestSupport {
cleanup:
context?.stop()
}
+
+ def 'idempotentConsumer'() {
+ setup:
+ def context = startContext([
+ 'myRepo': new MemoryIdempotentRepository()
+ ])
+
+ org.apache.camel.k.loader.yaml.TestSupport.mockEndpoint(context,'mock:idempotent') {
+ expectedMessageCount = 3
+ expectedBodiesReceived 'a', 'b', 'c'
+ }
+ org.apache.camel.k.loader.yaml.TestSupport.mockEndpoint(context,'mock:route') {
+ expectedMessageCount = 5
+ expectedBodiesReceived 'a', 'b', 'a2', 'b2', 'c'
+ }
+ when:
+ context.createProducerTemplate().with {
+ sendBodyAndHeader('direct:route', 'a', 'id', '1')
+ sendBodyAndHeader('direct:route', 'b', 'id', '2')
+ sendBodyAndHeader('direct:route', 'a2', 'id', '1')
+ sendBodyAndHeader('direct:route', 'b2', 'id', '2')
+ sendBodyAndHeader('direct:route', 'c', 'id', '3')
+ }
+ then:
+ MockEndpoint.assertIsSatisfied(context)
+ cleanup:
+ context?.stop()
+ }
+
}
diff --git a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/IdempotentConsumerTest.groovy b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/IdempotentConsumerTest.groovy
new file mode 100644
index 0000000..277f2c3
--- /dev/null
+++ b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/IdempotentConsumerTest.groovy
@@ -0,0 +1,54 @@
+/*
+ * 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.k.loader.yaml.parser
+
+import org.apache.camel.k.loader.yaml.TestSupport
+import org.apache.camel.model.IdempotentConsumerDefinition
+import org.apache.camel.model.SplitDefinition
+
+class IdempotentConsumerTest extends TestSupport {
+
+ def "definition with expression"() {
+ given:
+ def stepContext = stepContext('''
+ simple: "${header.id}"
+ ''')
+ when:
+ def processor = new IdempotentConsumerParser().toProcessor(stepContext)
+ then:
+ def p = processor as IdempotentConsumerDefinition
+
+ p.expression.language == 'simple'
+ p.expression.expression == '${header.id}'
+ }
+
+ def "definition with expression block"() {
+ given:
+ def stepContext = stepContext('''
+ expression:
+ simple: "${header.id}"
+ ''')
+ when:
+ def processor = new IdempotentConsumerParser().toProcessor(stepContext)
+ then:
+ with(processor, IdempotentConsumerDefinition) {
+ expression.language == 'simple'
+ expression.expression == '${header.id}'
+ }
+ }
+
+}
diff --git a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RoutesTest_idempotentConsumer.yaml b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RoutesTest_idempotentConsumer.yaml
new file mode 100644
index 0000000..36097e6
--- /dev/null
+++ b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RoutesTest_idempotentConsumer.yaml
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+- from:
+ uri: "direct:route"
+ steps:
+ - idempotent-consumer:
+ simple: "${header.id}"
+ message-id-repository-ref: "myRepo"
+ steps:
+ - to: "mock:idempotent"
+ - to: "mock:route"