This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch docs/yaml-dsl-tabs-alignment in repository https://gitbox.apache.org/repos/asf/camel.git
commit eaf3043636fbe3895bc41e1227198b78bb370268 Author: Claus Ibsen <[email protected]> AuthorDate: Sun Jun 14 22:29:29 2026 +0200 docs: add YAML DSL tabs to aggregate EIP and language docs Add [tabs] blocks with YAML DSL examples to: - aggregate-eip.adoc (3 tab blocks for controller, bean strategy, allowNull) - constant-language.adoc (2 tab blocks for setHeader examples) - ref-language.adoc (1 tab block for split with ref) - exchangeProperty-language.adoc (1 tab block for recipientList) - header-language.adoc (1 tab block for recipientList) - variable-language.adoc (1 tab block for recipientList) Co-Authored-By: Claude <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../docs/modules/eips/pages/aggregate-eip.adoc | 200 +++++++++++++++------ .../modules/languages/pages/constant-language.adoc | 67 +++++-- .../languages/pages/exchangeProperty-language.adoc | 34 +++- .../modules/languages/pages/header-language.adoc | 34 +++- .../docs/modules/languages/pages/ref-language.adoc | 47 +++-- .../modules/languages/pages/variable-language.adoc | 34 +++- 6 files changed, 319 insertions(+), 97 deletions(-) diff --git a/core/camel-core-engine/src/main/docs/modules/eips/pages/aggregate-eip.adoc b/core/camel-core-engine/src/main/docs/modules/eips/pages/aggregate-eip.adoc index 37cbc710cffb..c162ef4413e0 100644 --- a/core/camel-core-engine/src/main/docs/modules/eips/pages/aggregate-eip.adoc +++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/aggregate-eip.adoc @@ -377,6 +377,11 @@ configured, which can be accessed using `getAggregateController()` method. Though it may be easier to configure a controller in the route using `aggregateController` as shown below: +[tabs] +==== + +Java:: ++ [source,java] ---- private AggregateController controller = new DefaultAggregateController(); @@ -388,6 +393,47 @@ from("direct:start") .to("mock:aggregated"); ---- +XML:: ++ +[source,xml] +---- +<bean id="myController" class="org.apache.camel.processor.aggregate.DefaultAggregateController"/> + +<camelContext xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="direct:start"/> + <aggregate aggregationStrategy="myAppender" completionSize="10" + aggregateController="myController"> + <correlationExpression> + <header>id</header> + </correlationExpression> + <to uri="mock:result"/> + </aggregate> + </route> +</camelContext> +---- + +YAML:: ++ +[source,yaml] +---- +- route: + from: + uri: direct:start + steps: + - aggregate: + aggregateController: myController + aggregationStrategy: myAppender + completionSize: 10 + correlationExpression: + header: + expression: id + steps: + - to: + uri: mock:result +---- +==== + Then there is API on `AggregateController` to force completion. For example, to complete a group with key foo: @@ -406,29 +452,6 @@ There is also a method to complete all groups: int groups = controller.forceCompletionOfAllGroups(); ---- -The controller can also be used in XML DSL using the `aggregateController` to -refer to a bean with the controller implementation, which is looked up in the registry. - -When using Spring XML, you can create the bean with `<bean>` as shown: - -[source,xml] ----- -<bean id="myController" class="org.apache.camel.processor.aggregate.DefaultAggregateController"/> - -<camelContext xmlns="http://camel.apache.org/schema/spring"> - <route> - <from uri="direct:start"/> - <aggregate aggregationStrategy="myAppender" completionSize="10" - aggregateController="myController"> - <correlationExpression> - <header>id</header> - </correlationExpression> - <to uri="mock:result"/> - </aggregate> - </route> -</camelContext> ----- - There is also JMX API on the aggregator which is available under the processors node in the Camel JMX tree. == Aggregating with Beans @@ -505,6 +528,11 @@ And then in the Camel route we create an instance of our bean, and then refer to the bean in the route using `bean` method from `org.apache.camel.builder.AggregationStrategies` as shown: +[tabs] +==== + +Java:: ++ [source,java] ---- private MyBodyAppender appender = new MyBodyAppender(); @@ -517,7 +545,47 @@ public void configure() throws Exception { } ---- -We can also provide the bean class type directly: +XML:: ++ +[source,xml] +---- +<bean id="myAppender" class="com.foo.MyBodyAppender"/> + +<camelContext xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="direct:start"/> + <aggregate aggregationStrategy="myAppender" aggregationStrategyMethodName="append" completionSize="3"> + <correlationExpression> + <constant>true</constant> + </correlationExpression> + <to uri="mock:result"/> + </aggregate> + </route> +</camelContext> +---- + +YAML:: ++ +[source,yaml] +---- +- route: + from: + uri: direct:start + steps: + - aggregate: + aggregationStrategy: myAppender + aggregationStrategyMethodName: append + completionSize: 3 + correlationExpression: + constant: + expression: "true" + steps: + - to: + uri: mock:result +---- +==== + +In Java DSL, you can also provide the bean class type directly: [source,java] ---- @@ -555,35 +623,14 @@ public class MyBodyAppender { } ---- -If you are using XML DSL, then we need to declare a `<bean>` with the bean: - -[source,xml] ----- -<bean id="myAppender" class="com.foo.MyBodyAppender"/> ----- - -And in the Camel route we use `aggregationStrategy` to refer to the bean by its -id, and the `strategyMethodName` can be used to define the method name -to call: - -[source,xml] ----- -<camelContext xmlns="http://camel.apache.org/schema/spring"> - <route> - <from uri="direct:start"/> - <aggregate aggregationStrategy="myAppender" aggregationStrategyMethodName="append" completionSize="3"> - <correlationExpression> - <constant>true</constant> - </correlationExpression> - <to uri="mock:result"/> - </aggregate> - </route> -</camelContext> ----- - -When using XML DSL, you can also specify the bean class directly in `aggregationStrategy` +When using XML or YAML DSL, you can also specify the bean class directly in `aggregationStrategy` using the `#class:` syntax as shown: +[tabs] +==== + +XML:: ++ [source,xml] ---- <route> @@ -597,8 +644,26 @@ using the `#class:` syntax as shown: </route> ---- -You can use this in XML DSL when you are not using the classic Spring XML files ( -where you use XML only for Camel routes). +YAML:: ++ +[source,yaml] +---- +- route: + from: + uri: direct:start + steps: + - aggregate: + aggregationStrategy: "#class:com.foo.MyBodyAppender" + aggregationStrategyMethodName: append + completionSize: 3 + correlationExpression: + constant: + expression: "true" + steps: + - to: + uri: mock:result +---- +==== === Aggregating when no data @@ -647,9 +712,14 @@ If we didn't do this, then on timeout the append method would normally not be invoked, meaning the xref:content-enricher.adoc[Content Enricher] did not merge/change the message. -In XML DSL you would configure the `strategyMethodAllowNull` option and +In XML and YAML DSL you would configure the `strategyMethodAllowNull` option and set it to `true` as shown below: +[tabs] +==== + +XML:: ++ [source,xml] ---- <camelContext xmlns="http://camel.apache.org/schema/spring"> @@ -668,6 +738,28 @@ set it to `true` as shown below: </camelContext> ---- +YAML:: ++ +[source,yaml] +---- +- route: + from: + uri: direct:start + steps: + - aggregate: + aggregationStrategy: myAppender + aggregationStrategyMethodName: append + aggregationStrategyMethodAllowNull: true + completionSize: 3 + correlationExpression: + constant: + expression: "true" + steps: + - to: + uri: mock:result +---- +==== + === Aggregating with different body types When, for example, using `strategyMethodAllowNull` as `true`, then the diff --git a/core/camel-core-languages/src/main/docs/modules/languages/pages/constant-language.adoc b/core/camel-core-languages/src/main/docs/modules/languages/pages/constant-language.adoc index c1cbacb927de..2bbcc244a6eb 100644 --- a/core/camel-core-languages/src/main/docs/modules/languages/pages/constant-language.adoc +++ b/core/camel-core-languages/src/main/docs/modules/languages/pages/constant-language.adoc @@ -33,6 +33,20 @@ include::partial$language-options.adoc[] The `setHeader` EIP can utilize a constant expression like: +[tabs] +==== + +Java:: ++ +[source,java] +---- +from("seda:a") + .setHeader("theHeader", constant("the value")) + .to("mock:b"); +---- + +XML:: ++ [source,xml] ---- <route> @@ -44,18 +58,27 @@ expression like: </route> ---- -in this case, the message coming from the seda:a -endpoint will have the header with key `theHeader` -set its value as `the value` (string type). - -And the same example using Java DSL: - -[source,java] +YAML:: ++ +[source,yaml] ---- -from("seda:a") - .setHeader("theHeader", constant("the value")) - .to("mock:b"); +- route: + from: + uri: seda:a + steps: + - setHeader: + name: theHeader + expression: + constant: + expression: the value + - to: + uri: mock:b ---- +==== + +In this case, the message coming from the seda:a +endpoint will have the header with key `theHeader` +set its value as `the value` (string type). === Specifying type of value @@ -64,6 +87,11 @@ as a `String` value, which happens when using XML or YAML DSL: For example to set a header with `int` type you can do: +[tabs] +==== + +XML:: ++ [source,xml] ---- <route> @@ -75,6 +103,25 @@ For example to set a header with `int` type you can do: </route> ---- +YAML:: ++ +[source,yaml] +---- +- route: + from: + uri: seda:a + steps: + - setHeader: + name: zipCode + expression: + constant: + resultType: int + expression: "90210" + - to: + uri: mock:b +---- +==== + == Loading constant from external resource diff --git a/core/camel-core-languages/src/main/docs/modules/languages/pages/exchangeProperty-language.adoc b/core/camel-core-languages/src/main/docs/modules/languages/pages/exchangeProperty-language.adoc index f3cf32e5800e..b7789d9638d5 100644 --- a/core/camel-core-languages/src/main/docs/modules/languages/pages/exchangeProperty-language.adoc +++ b/core/camel-core-languages/src/main/docs/modules/languages/pages/exchangeProperty-language.adoc @@ -25,6 +25,18 @@ include::partial$language-options.adoc[] The `recipientList` EIP can utilize a exchangeProperty like: +[tabs] +==== + +Java:: ++ +[source,java] +---- +from("direct:a").recipientList(exchangeProperty("myProperty")); +---- + +XML:: ++ [source,xml] ---- <route> @@ -35,15 +47,23 @@ The `recipientList` EIP can utilize a exchangeProperty like: </route> ---- -In this case, the list of recipients are contained in the property -'myProperty'. - -And the same example in Java DSL: - -[source,java] +YAML:: ++ +[source,yaml] ---- -from("direct:a").recipientList(exchangeProperty("myProperty")); +- route: + from: + uri: direct:a + steps: + - recipientList: + expression: + exchangeProperty: + expression: myProperty ---- +==== + +In this case, the list of recipients are contained in the property +'myProperty'. == Dependencies diff --git a/core/camel-core-languages/src/main/docs/modules/languages/pages/header-language.adoc b/core/camel-core-languages/src/main/docs/modules/languages/pages/header-language.adoc index 115a3dec077f..b0b1b08df5a7 100644 --- a/core/camel-core-languages/src/main/docs/modules/languages/pages/header-language.adoc +++ b/core/camel-core-languages/src/main/docs/modules/languages/pages/header-language.adoc @@ -25,6 +25,18 @@ include::partial$language-options.adoc[] The `recipientList` EIP can utilize a header: +[tabs] +==== + +Java:: ++ +[source,java] +---- +from("direct:a").recipientList(header("myHeader")); +---- + +XML:: ++ [source,xml] ---- <route> @@ -35,15 +47,23 @@ The `recipientList` EIP can utilize a header: </route> ---- -In this case, the list of recipients are contained in the header -'myHeader'. - -And the same example in Java DSL: - -[source,java] +YAML:: ++ +[source,yaml] ---- -from("direct:a").recipientList(header("myHeader")); +- route: + from: + uri: direct:a + steps: + - recipientList: + expression: + header: + expression: myHeader ---- +==== + +In this case, the list of recipients are contained in the header +'myHeader'. == Dependencies diff --git a/core/camel-core-languages/src/main/docs/modules/languages/pages/ref-language.adoc b/core/camel-core-languages/src/main/docs/modules/languages/pages/ref-language.adoc index 640a1e54f935..00df8228fcd5 100644 --- a/core/camel-core-languages/src/main/docs/modules/languages/pages/ref-language.adoc +++ b/core/camel-core-languages/src/main/docs/modules/languages/pages/ref-language.adoc @@ -25,9 +25,21 @@ include::partial$language-options.adoc[] == Example usage -The Splitter EIP in XML DSL can utilize a custom -expression using `<ref>` like: +The Splitter EIP can utilize a custom +expression using `ref` like: +[tabs] +==== + +Java:: ++ +[source,java] +---- +from("seda:a").split().ref("myExpression").to("seda:b"); +---- + +XML:: ++ [source,xml] ---- <bean id="myExpression" class="com.mycompany.MyCustomExpression"/> @@ -35,24 +47,35 @@ expression using `<ref>` like: <route> <from uri="seda:a"/> <split> - <ref>myExpression</ref> + <ref>myExpression</ref> <to uri="mock:b"/> - </split> + </split> </route> ---- -in this case, the message coming from the seda:a +YAML:: ++ +[source,yaml] +---- +- route: + from: + uri: seda:a + steps: + - split: + expression: + ref: + expression: myExpression + steps: + - to: + uri: mock:b +---- +==== + +In this case, the message coming from the seda:a endpoint will be split using a custom `Expression` which has the id `myExpression` in the xref:manual:ROOT:registry.adoc[Registry]. -And the same example using Java DSL: - -[source,java] ----- -from("seda:a").split().ref("myExpression").to("seda:b"); ----- - == Dependencies The Ref language is part of *camel-core*. diff --git a/core/camel-core-languages/src/main/docs/modules/languages/pages/variable-language.adoc b/core/camel-core-languages/src/main/docs/modules/languages/pages/variable-language.adoc index 7e7c2098bd59..586f711bf96b 100644 --- a/core/camel-core-languages/src/main/docs/modules/languages/pages/variable-language.adoc +++ b/core/camel-core-languages/src/main/docs/modules/languages/pages/variable-language.adoc @@ -25,6 +25,18 @@ include::partial$language-options.adoc[] The `recipientList` EIP can utilize a variable: +[tabs] +==== + +Java:: ++ +[source,java] +---- +from("direct:a").recipientList(variable("myVar")); +---- + +XML:: ++ [source,xml] ---- <route> @@ -35,15 +47,23 @@ The `recipientList` EIP can utilize a variable: </route> ---- -In this case, the list of recipients are contained in the variable -'myVar'. - -And the same example in Java DSL: - -[source,java] +YAML:: ++ +[source,yaml] ---- -from("direct:a").recipientList(variable("myVar")); +- route: + from: + uri: direct:a + steps: + - recipientList: + expression: + variable: + expression: myVar ---- +==== + +In this case, the list of recipients are contained in the variable +'myVar'. == Dependencies
