You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2025/03/27 11:52:05 UTC
(camel-quarkus-examples) branch camel-quarkus-main updated: Convert timer-log example to use YAML instead of XML DSL
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch camel-quarkus-main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus-examples.git
The following commit(s) were added to refs/heads/camel-quarkus-main by this push:
new 0a6baf7 Convert timer-log example to use YAML instead of XML DSL
0a6baf7 is described below
commit 0a6baf7f9edda0874c4f09a88284f4eb4b0cbbe2
Author: James Netherton <ja...@gmail.com>
AuthorDate: Thu Mar 27 11:23:26 2025 +0000
Convert timer-log example to use YAML instead of XML DSL
---
timer-log/README.adoc | 2 +-
timer-log/pom.xml | 4 +--
.../acme/timer/log/ExchangeFormatterProducer.java | 4 +--
.../src/main/resources/application.properties | 2 --
timer-log/src/main/resources/camel/my-routes.yaml | 24 +++++++++++++++
timer-log/src/main/resources/routes/my-routes.xml | 35 ----------------------
.../test/java/org/acme/timer/log/TimerLogTest.java | 5 ++--
7 files changed, 31 insertions(+), 45 deletions(-)
diff --git a/timer-log/README.adoc b/timer-log/README.adoc
index 3ec5203..1d7d21a 100644
--- a/timer-log/README.adoc
+++ b/timer-log/README.adoc
@@ -20,7 +20,7 @@ TIP: Please refer to the Development mode section of
https://camel.apache.org/camel-quarkus/latest/first-steps.html#_development_mode[Camel Quarkus User guide] for more details.
Then look at the log output in the console. There are 2 log messages. One generated from a route defined using the Java DSL in class `TimerRoute` and
-another defined using the XML DSL in `src/main/resources/routes/my-routes.xml`.
+another defined using the YAML DSL in `src/main/resources/camel/my-routes.yaml`.
As we run the example in Quarkus Dev Mode, you can edit the source code and have live updates.
For example, try to change the default greeting message in `GreetingBean` to `Bye World`.
diff --git a/timer-log/pom.xml b/timer-log/pom.xml
index 55d7e89..4dd4a9b 100644
--- a/timer-log/pom.xml
+++ b/timer-log/pom.xml
@@ -90,10 +90,10 @@
<artifactId>camel-quarkus-timer</artifactId>
</dependency>
- <!-- To demonstrate an XML route -->
+ <!-- To demonstrate a YAML route -->
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
- <artifactId>camel-quarkus-xml-io-dsl</artifactId>
+ <artifactId>camel-quarkus-yaml-dsl</artifactId>
</dependency>
<!-- Test -->
diff --git a/timer-log/src/main/java/org/acme/timer/log/ExchangeFormatterProducer.java b/timer-log/src/main/java/org/acme/timer/log/ExchangeFormatterProducer.java
index 7a9c2da..66b80e2 100644
--- a/timer-log/src/main/java/org/acme/timer/log/ExchangeFormatterProducer.java
+++ b/timer-log/src/main/java/org/acme/timer/log/ExchangeFormatterProducer.java
@@ -57,8 +57,8 @@ public class ExchangeFormatterProducer {
switch (toEndpoint) {
case "log://timer":
return LogColor.BLUE.apply("Java DSL: " + body);
- case "log://timer-xml":
- return LogColor.YELLOW.apply("XML DSL: " + body);
+ case "log://timer-yaml":
+ return LogColor.YELLOW.apply("YAML DSL: " + body);
default:
return body;
}
diff --git a/timer-log/src/main/resources/application.properties b/timer-log/src/main/resources/application.properties
index 6ba528f..116966c 100644
--- a/timer-log/src/main/resources/application.properties
+++ b/timer-log/src/main/resources/application.properties
@@ -25,7 +25,5 @@ quarkus.log.file.enable = true
#
camel.context.name = quarkus-camel-example-timer-log
-camel.main.routes-include-pattern= classpath:routes/my-routes.xml
-
timer.period=1s
greeting.message=Hello World!
diff --git a/timer-log/src/main/resources/camel/my-routes.yaml b/timer-log/src/main/resources/camel/my-routes.yaml
new file mode 100644
index 0000000..79789a0
--- /dev/null
+++ b/timer-log/src/main/resources/camel/my-routes.yaml
@@ -0,0 +1,24 @@
+#
+# 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.
+#
+
+- route:
+ id: "yaml-route"
+ from:
+ uri: "timer:from-yaml?period={{timer.period}}"
+ steps:
+ - to: "bean:greeting?method=greet"
+ - to: "log:timer-yaml"
diff --git a/timer-log/src/main/resources/routes/my-routes.xml b/timer-log/src/main/resources/routes/my-routes.xml
deleted file mode 100644
index f1dff09..0000000
--- a/timer-log/src/main/resources/routes/my-routes.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?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.
-
--->
-<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="http://camel.apache.org/schema/spring"
- xsi:schemaLocation="
- http://camel.apache.org/schema/spring
- https://camel.apache.org/schema/spring/camel-spring.xsd">
-
- <route id="xml-route">
- <from uri="timer:from-xml?period={{timer.period}}"/>
-
- <!-- Invoke the CDI GreetingBean -->
- <bean ref="greeting" method="greet"/>
-
- <to uri="log:timer-xml"/>
- </route>
-
-</routes>
\ No newline at end of file
diff --git a/timer-log/src/test/java/org/acme/timer/log/TimerLogTest.java b/timer-log/src/test/java/org/acme/timer/log/TimerLogTest.java
index 90986c6..dfa840e 100644
--- a/timer-log/src/test/java/org/acme/timer/log/TimerLogTest.java
+++ b/timer-log/src/test/java/org/acme/timer/log/TimerLogTest.java
@@ -16,7 +16,6 @@
*/
package org.acme.timer.log;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.concurrent.TimeUnit;
@@ -37,8 +36,8 @@ public class TimerLogTest {
String greeting = config.getValue("greeting.message", String.class);
await().atMost(10L, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> {
- String log = new String(Files.readAllBytes(Paths.get("target/quarkus.log")), StandardCharsets.UTF_8);
- return log.contains("Java DSL: " + greeting) && log.contains("XML DSL: " + greeting);
+ String log = Files.readString(Paths.get("target/quarkus.log"));
+ return log.contains("Java DSL: " + greeting) && log.contains("YAML DSL: " + greeting);
});
}
}