This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-quarkus-examples.git
commit 6befb8ee0d35903a0be4853e64c84cfa28f09783 Author: James Netherton <jamesnether...@gmail.com> AuthorDate: Thu Jun 23 12:52:04 2022 +0100 Reduce the number of timer-log examples --- docs/modules/ROOT/attachments/examples.json | 15 -- timer-log-cdi/README.adoc | 60 ----- timer-log-cdi/pom.xml | 280 -------------------- .../src/main/java/org/acme/cdi/Configurations.java | 41 --- .../src/main/java/org/acme/cdi/TimerRoute.java | 54 ---- .../src/main/resources/application.properties | 27 -- .../src/test/java/org/acme/cdi/TimerLogCdiIT.java | 24 -- .../test/java/org/acme/cdi/TimerLogCdiTest.java | 40 --- timer-log-spring/README.adoc | 60 ----- timer-log-spring/pom.xml | 284 -------------------- .../src/main/java/org/acme/spring/Counter.java | 37 --- .../src/main/java/org/acme/spring/TimerRoute.java | 48 ---- .../src/main/resources/application.properties | 33 --- .../java/org/acme/spring/TimerLogSpringIT.java | 24 -- .../java/org/acme/spring/TimerLogSpringTest.java | 39 --- timer-log-xml/README.adoc | 61 ----- timer-log-xml/pom.xml | 287 --------------------- .../src/main/java/org/acme/xml/DummyClass.java | 20 -- .../src/main/java/org/acme/xml/package-info.java | 19 -- .../src/main/resources/application.properties | 34 --- .../test/java/org/acme/xml/TimerLogXmlTest.java | 40 --- .../test/java/org/acme/xml/TimerLogXmlXmlIT.java | 24 -- timer-log/README.adoc | 12 +- timer-log/pom.xml | 12 +- .../acme/timer/log/ExchangeFormatterProducer.java | 69 +++++ .../main/java/org/acme/timer/log/GreetingBean.java | 25 +- .../main/java/org/acme/timer/log/TimerRoute.java | 8 +- .../src/main/resources/application.properties | 5 + .../src/main/resources/routes/my-routes.xml | 8 +- .../test/java/org/acme/timer/log/TimerLogTest.java | 8 +- 30 files changed, 124 insertions(+), 1574 deletions(-) diff --git a/docs/modules/ROOT/attachments/examples.json b/docs/modules/ROOT/attachments/examples.json index 1302155..bfe2be9 100644 --- a/docs/modules/ROOT/attachments/examples.json +++ b/docs/modules/ROOT/attachments/examples.json @@ -1,9 +1,4 @@ [ - { - "title": "Configure a Camel component using CDI", - "description": "Demonstrates how to set-up a Camel component (the `log` component in this case) programmatically using CDI", - "link": "https://github.com/apache/camel-quarkus-examples/tree/main/timer-log-cdi" - }, { "title": "Connecting to a JDBC DataSource", "description": "Shows how to connect to a Database using Datastores.", @@ -64,11 +59,6 @@ "description": "Demonstrates how to create a REST service using the Camel REST DSL and Jackson.", "link": "https://github.com/apache/camel-quarkus-examples/tree/main/rest-json" }, - { - "title": "Spring Dependency Injection", - "description": "Shows how to use Spring Dependency Injection when defining routes on Camel Quarkus.", - "link": "https://github.com/apache/camel-quarkus-examples/tree/main/timer-log-spring" - }, { "title": "Timer Hello World", "description": "Uses the Camel timer component to output a Hello world message to the console", @@ -78,10 +68,5 @@ "title": "Tokenize a CSV file", "description": "Shows how to define a Camel route in XML for tokenizing a CSV a file.", "link": "https://github.com/apache/camel-quarkus-examples/tree/main/file-split-log-xml" - }, - { - "title": "XML Hello World", - "description": "Shows how to define Camel routes using XML.", - "link": "https://github.com/apache/camel-quarkus-examples/tree/main/timer-log-xml" } ] \ No newline at end of file diff --git a/timer-log-cdi/README.adoc b/timer-log-cdi/README.adoc deleted file mode 100644 index 4b41683..0000000 --- a/timer-log-cdi/README.adoc +++ /dev/null @@ -1,60 +0,0 @@ -= Configure a Camel component using CDI: A Camel Quarkus example -:cq-example-description: An example that demonstrates how to set-up a Camel component (the `log` component in this case) programmatically using CDI - -{cq-description} - -TIP: Check the https://camel.apache.org/camel-quarkus/latest/first-steps.html[Camel Quarkus User guide] for prerequisites -and other general information. - -== Start in the Development mode - -[source,shell] ----- -$ mvn clean compile quarkus:dev ----- - -The above command compiles the project, starts the application and lets the Quarkus tooling watch for changes in your -workspace. Any modifications in your project will automatically take effect in the running application. - -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. As we run the example in Quarkus Dev Mode, you can edit the source code and have live updates. -For example try to change `Incremented the counter` to `Counter state` in the message body or change the property `timer.period` in application.properties - -=== Package and run the application - -Once you are done with developing you may want to package and run the application. - -TIP: Find more details about the JVM mode and Native mode in the Package and run section of -https://camel.apache.org/camel-quarkus/latest/first-steps.html#_package_and_run_the_application[Camel Quarkus User guide] - -==== JVM mode - -[source,shell] ----- -$ mvn clean package -$ java -jar target/quarkus-app/quarkus-run.jar -... -[io.quarkus] (main) camel-quarkus-examples-... started in 1.163s. ----- - -==== Native mode - -IMPORTANT: Native mode requires having GraalVM and other tools installed. Please check the Prerequisites section -of https://camel.apache.org/camel-quarkus/latest/first-steps.html#_prerequisites[Camel Quarkus User guide]. - -To prepare a native executable using GraalVM, run the following command: - -[source,shell] ----- -$ mvn clean package -Pnative -$ ./target/*-runner -... -[io.quarkus] (main) camel-quarkus-examples-... started in 0.013s. -... ----- - -== Feedback - -Please report bugs and propose improvements via https://github.com/apache/camel-quarkus/issues[GitHub issues of Camel Quarkus] project. diff --git a/timer-log-cdi/pom.xml b/timer-log-cdi/pom.xml deleted file mode 100644 index 14c67a1..0000000 --- a/timer-log-cdi/pom.xml +++ /dev/null @@ -1,280 +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. - ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <artifactId>camel-quarkus-examples-timer-log-cdi</artifactId> - <groupId>org.apache.camel.quarkus.examples</groupId> - <version>2.11.0-SNAPSHOT</version> - - <name>Camel Quarkus :: Examples :: Timer Log CDI</name> - <description>Camel Quarkus Example :: Timer to Log CDI</description> - - <properties> - <quarkus.platform.version>2.10.0.Final</quarkus.platform.version> - <camel-quarkus.platform.version>2.11.0-SNAPSHOT</camel-quarkus.platform.version> - - <quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id> - <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id> - <camel-quarkus.platform.group-id>org.apache.camel.quarkus</camel-quarkus.platform.group-id> - <camel-quarkus.platform.artifact-id>camel-quarkus-bom</camel-quarkus.platform.artifact-id> - - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> - <maven.compiler.target>11</maven.compiler.target> - <maven.compiler.source>11</maven.compiler.source> - <maven.compiler.testTarget>${maven.compiler.target}</maven.compiler.testTarget> - <maven.compiler.testSource>${maven.compiler.source}</maven.compiler.testSource> - - <formatter-maven-plugin.version>2.17.1</formatter-maven-plugin.version> - <impsort-maven-plugin.version>1.3.2</impsort-maven-plugin.version> - <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version> - <maven-jar-plugin.version>3.2.0</maven-jar-plugin.version> - <maven-resources-plugin.version>3.1.0</maven-resources-plugin.version> - <maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version> - <mycila-license.version>3.0</mycila-license.version> - </properties> - - <dependencyManagement> - <dependencies> - <!-- Import BOM --> - <dependency> - <groupId>${quarkus.platform.group-id}</groupId> - <artifactId>${quarkus.platform.artifact-id}</artifactId> - <version>${quarkus.platform.version}</version> - <type>pom</type> - <scope>import</scope> - </dependency> - <dependency> - <groupId>${camel-quarkus.platform.group-id}</groupId> - <artifactId>${camel-quarkus.platform.artifact-id}</artifactId> - <version>${camel-quarkus.platform.version}</version> - <type>pom</type> - <scope>import</scope> - </dependency> - </dependencies> - </dependencyManagement> - - <dependencies> - <dependency> - <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-log</artifactId> - </dependency> - <dependency> - <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-microprofile-health</artifactId> - </dependency> - <dependency> - <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-timer</artifactId> - </dependency> - - <!-- Test --> - <dependency> - <groupId>io.quarkus</groupId> - <artifactId>quarkus-junit5</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.awaitility</groupId> - <artifactId>awaitility</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <pluginManagement> - <plugins> - - <plugin> - <groupId>net.revelc.code.formatter</groupId> - <artifactId>formatter-maven-plugin</artifactId> - <version>${formatter-maven-plugin.version}</version> - <configuration> - <configFile>${maven.multiModuleProjectDirectory}/eclipse-formatter-config.xml</configFile> - <lineEnding>LF</lineEnding> - </configuration> - </plugin> - - <plugin> - <groupId>net.revelc.code</groupId> - <artifactId>impsort-maven-plugin</artifactId> - <version>${impsort-maven-plugin.version}</version> - <configuration> - <groups>java.,javax.,org.w3c.,org.xml.,junit.</groups> - <removeUnused>true</removeUnused> - <staticAfter>true</staticAfter> - <staticGroups>java.,javax.,org.w3c.,org.xml.,junit.</staticGroups> - </configuration> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>${maven-compiler-plugin.version}</version> - <configuration> - <showDeprecation>true</showDeprecation> - <showWarnings>true</showWarnings> - <compilerArgs> - <arg>-Xlint:unchecked</arg> - </compilerArgs> - </configuration> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <version>${maven-surefire-plugin.version}</version> - <configuration> - <failIfNoTests>false</failIfNoTests> - <systemProperties> - <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> - </systemProperties> - </configuration> - </plugin> - - <plugin> - <groupId>${quarkus.platform.group-id}</groupId> - <artifactId>quarkus-maven-plugin</artifactId> - <version>${quarkus.platform.version}</version> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-failsafe-plugin</artifactId> - <version>${maven-surefire-plugin.version}</version> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <version>${maven-jar-plugin.version}</version> - </plugin> - - <plugin> - <groupId>com.mycila</groupId> - <artifactId>license-maven-plugin</artifactId> - <version>${mycila-license.version}</version> - <configuration> - <failIfUnknown>true</failIfUnknown> - <header>${maven.multiModuleProjectDirectory}/header.txt</header> - <excludes> - <exclude>**/*.adoc</exclude> - <exclude>**/*.txt</exclude> - <exclude>**/LICENSE.txt</exclude> - <exclude>**/LICENSE</exclude> - <exclude>**/NOTICE.txt</exclude> - <exclude>**/NOTICE</exclude> - <exclude>**/README</exclude> - <exclude>**/pom.xml.versionsBackup</exclude> - </excludes> - <mapping> - <java>SLASHSTAR_STYLE</java> - <properties>CAMEL_PROPERTIES_STYLE</properties> - <kt>SLASHSTAR_STYLE</kt> - </mapping> - <headerDefinitions> - <headerDefinition>${maven.multiModuleProjectDirectory}/license-properties-headerdefinition.xml</headerDefinition> - </headerDefinitions> - </configuration> - </plugin> - </plugins> - </pluginManagement> - - <plugins> - <plugin> - <groupId>${quarkus.platform.group-id}</groupId> - <artifactId>quarkus-maven-plugin</artifactId> - <executions> - <execution> - <id>build</id> - <goals> - <goal>build</goal> - </goals> - </execution> - </executions> - </plugin> - - <plugin> - <groupId>net.revelc.code.formatter</groupId> - <artifactId>formatter-maven-plugin</artifactId> - <executions> - <execution> - <id>format</id> - <goals> - <goal>format</goal> - </goals> - <phase>process-sources</phase> - </execution> - </executions> - </plugin> - - <plugin> - <groupId>net.revelc.code</groupId> - <artifactId>impsort-maven-plugin</artifactId> - <executions> - <execution> - <id>sort-imports</id> - <goals> - <goal>sort</goal> - </goals> - <phase>process-sources</phase> - </execution> - </executions> - </plugin> - </plugins> - </build> - - <profiles> - <profile> - <id>native</id> - <activation> - <property> - <name>native</name> - </property> - </activation> - <properties> - <quarkus.package.type>native</quarkus.package.type> - </properties> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-failsafe-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>integration-test</goal> - <goal>verify</goal> - </goals> - <configuration> - <systemPropertyVariables> - <quarkus.package.type>${quarkus.package.type}</quarkus.package.type> - </systemPropertyVariables> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - </profile> - </profiles> - -</project> diff --git a/timer-log-cdi/src/main/java/org/acme/cdi/Configurations.java b/timer-log-cdi/src/main/java/org/acme/cdi/Configurations.java deleted file mode 100644 index adcdb91..0000000 --- a/timer-log-cdi/src/main/java/org/acme/cdi/Configurations.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.acme.cdi; - -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Named; - -import org.apache.camel.component.log.LogComponent; -import org.apache.camel.support.processor.DefaultExchangeFormatter; - -@ApplicationScoped -public class Configurations { - /** - * Produces a {@link LogComponent} instance with a custom exchange formatter set-up. - */ - @Named - LogComponent log() { - DefaultExchangeFormatter formatter = new DefaultExchangeFormatter(); - formatter.setShowExchangePattern(false); - formatter.setShowBodyType(false); - - LogComponent component = new LogComponent(); - component.setExchangeFormatter(formatter); - - return component; - } -} diff --git a/timer-log-cdi/src/main/java/org/acme/cdi/TimerRoute.java b/timer-log-cdi/src/main/java/org/acme/cdi/TimerRoute.java deleted file mode 100644 index 147772a..0000000 --- a/timer-log-cdi/src/main/java/org/acme/cdi/TimerRoute.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.acme.cdi; - -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; - -import org.apache.camel.builder.RouteBuilder; -import org.eclipse.microprofile.config.inject.ConfigProperty; - -/** - * A {@link RouteBuilder} demonstrating the use of CDI (Contexts and Dependency Injection). - * <p> - * Note that for the {@code @Inject} and {@code @ConfigProperty} annotations to work, this class has to be annotated - * with {@code @ApplicationScoped}. - */ -@ApplicationScoped -public class TimerRoute extends RouteBuilder { - - /** - * {@code timer.period} is defined in {@code src/main/resources/application.properties} - */ - @ConfigProperty(name = "timer.period", defaultValue = "1000") - String period; - - /** - * An injected bean - */ - @Inject - Counter counter; - - @Override - public void configure() throws Exception { - fromF("timer:foo?period=%s", period) - .setBody(exchange -> "Incremented the counter: " + counter.increment()) - // the configuration of the log component is done programmatically using CDI - // by the org.acme.timer.Beans::log method. - .to("log:example"); - } -} diff --git a/timer-log-cdi/src/main/resources/application.properties b/timer-log-cdi/src/main/resources/application.properties deleted file mode 100644 index 2346366..0000000 --- a/timer-log-cdi/src/main/resources/application.properties +++ /dev/null @@ -1,27 +0,0 @@ -## --------------------------------------------------------------------------- -## 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. -## --------------------------------------------------------------------------- - -# -# Quarkus -# -quarkus.banner.enabled = false -quarkus.log.file.enable = true - -# -# Integration -# -timer.period = 5000 diff --git a/timer-log-cdi/src/test/java/org/acme/cdi/TimerLogCdiIT.java b/timer-log-cdi/src/test/java/org/acme/cdi/TimerLogCdiIT.java deleted file mode 100644 index be92eb7..0000000 --- a/timer-log-cdi/src/test/java/org/acme/cdi/TimerLogCdiIT.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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.acme.cdi; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -class TimerLogCdiIT extends TimerLogCdiTest { - -} diff --git a/timer-log-cdi/src/test/java/org/acme/cdi/TimerLogCdiTest.java b/timer-log-cdi/src/test/java/org/acme/cdi/TimerLogCdiTest.java deleted file mode 100644 index 9e83092..0000000 --- a/timer-log-cdi/src/test/java/org/acme/cdi/TimerLogCdiTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.acme.cdi; - -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.concurrent.TimeUnit; - -import io.quarkus.test.junit.QuarkusTest; -import org.junit.jupiter.api.Test; - -import static org.awaitility.Awaitility.await; - -@QuarkusTest -public class TimerLogCdiTest { - - @Test - public void testTimerLog() { - 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("Incremented the counter"); - }); - } - -} diff --git a/timer-log-spring/README.adoc b/timer-log-spring/README.adoc deleted file mode 100644 index de7c04a..0000000 --- a/timer-log-spring/README.adoc +++ /dev/null @@ -1,60 +0,0 @@ -= Spring Dependency Injection: A Camel Quarkus example -:cq-example-description: An example that shows how to use Spring Dependency Injection when defining routes on Camel Quarkus. - -{cq-description} - -TIP: Check the https://camel.apache.org/camel-quarkus/latest/first-steps.html[Camel Quarkus User guide] for prerequisites -and other general information. - -== Start in the Development mode - -[source,shell] ----- -$ mvn clean compile quarkus:dev ----- - -The above command compiles the project, starts the application and lets the Quarkus tooling watch for changes in your -workspace. Any modifications in your project will automatically take effect in the running application. - -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. As we run the example in Quarkus Dev Mode, you can edit the source code and have live updates. -For example try to change `Incremented the counter` to `Counter state` in the message body or change the property `timer.period` in application.properties - -=== Package and run the application - -Once you are done with developing you may want to package and run the application. - -TIP: Find more details about the JVM mode and Native mode in the Package and run section of -https://camel.apache.org/camel-quarkus/latest/first-steps.html#_package_and_run_the_application[Camel Quarkus User guide] - -==== JVM mode - -[source,shell] ----- -$ mvn clean package -$ java -jar target/quarkus-app/quarkus-run.jar -... -[io.quarkus] (main) camel-quarkus-examples-... started in 0.497s. ----- - -==== Native mode - -IMPORTANT: Native mode requires having GraalVM and other tools installed. Please check the Prerequisites section -of https://camel.apache.org/camel-quarkus/latest/first-steps.html#_prerequisites[Camel Quarkus User guide]. - -To prepare a native executable using GraalVM, run the following command: - -[source,shell] ----- -$ mvn clean package -Pnative -$ ./target/*-runner -... -[io.quarkus] (main) camel-quarkus-examples-... started in 0.007s. -... ----- - -== Feedback - -Please report bugs and propose improvements via https://github.com/apache/camel-quarkus/issues[GitHub issues of Camel Quarkus] project. diff --git a/timer-log-spring/pom.xml b/timer-log-spring/pom.xml deleted file mode 100644 index b995d50..0000000 --- a/timer-log-spring/pom.xml +++ /dev/null @@ -1,284 +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. - ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <artifactId>camel-quarkus-examples-timer-log-spring</artifactId> - <groupId>org.apache.camel.quarkus.examples</groupId> - <version>2.11.0-SNAPSHOT</version> - - <name>Camel Quarkus :: Examples :: Timer Log Spring</name> - <description>Camel Quarkus Example :: Timer to Log Spring</description> - - <properties> - <quarkus.platform.version>2.10.0.Final</quarkus.platform.version> - <camel-quarkus.platform.version>2.11.0-SNAPSHOT</camel-quarkus.platform.version> - - <quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id> - <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id> - <camel-quarkus.platform.group-id>org.apache.camel.quarkus</camel-quarkus.platform.group-id> - <camel-quarkus.platform.artifact-id>camel-quarkus-bom</camel-quarkus.platform.artifact-id> - - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> - <maven.compiler.target>11</maven.compiler.target> - <maven.compiler.source>11</maven.compiler.source> - <maven.compiler.testTarget>${maven.compiler.target}</maven.compiler.testTarget> - <maven.compiler.testSource>${maven.compiler.source}</maven.compiler.testSource> - - <formatter-maven-plugin.version>2.17.1</formatter-maven-plugin.version> - <impsort-maven-plugin.version>1.3.2</impsort-maven-plugin.version> - <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version> - <maven-jar-plugin.version>3.2.0</maven-jar-plugin.version> - <maven-resources-plugin.version>3.1.0</maven-resources-plugin.version> - <maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version> - <mycila-license.version>3.0</mycila-license.version> - </properties> - - <dependencyManagement> - <dependencies> - <!-- Import BOM --> - <dependency> - <groupId>${quarkus.platform.group-id}</groupId> - <artifactId>${quarkus.platform.artifact-id}</artifactId> - <version>${quarkus.platform.version}</version> - <type>pom</type> - <scope>import</scope> - </dependency> - <dependency> - <groupId>${camel-quarkus.platform.group-id}</groupId> - <artifactId>${camel-quarkus.platform.artifact-id}</artifactId> - <version>${camel-quarkus.platform.version}</version> - <type>pom</type> - <scope>import</scope> - </dependency> - </dependencies> - </dependencyManagement> - - <dependencies> - <dependency> - <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-log</artifactId> - </dependency> - <dependency> - <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-microprofile-health</artifactId> - </dependency> - <dependency> - <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-timer</artifactId> - </dependency> - <dependency> - <groupId>io.quarkus</groupId> - <artifactId>quarkus-spring-di</artifactId> - </dependency> - - <!-- Test --> - <dependency> - <groupId>io.quarkus</groupId> - <artifactId>quarkus-junit5</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.awaitility</groupId> - <artifactId>awaitility</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <pluginManagement> - <plugins> - - <plugin> - <groupId>net.revelc.code.formatter</groupId> - <artifactId>formatter-maven-plugin</artifactId> - <version>${formatter-maven-plugin.version}</version> - <configuration> - <configFile>${maven.multiModuleProjectDirectory}/eclipse-formatter-config.xml</configFile> - <lineEnding>LF</lineEnding> - </configuration> - </plugin> - - <plugin> - <groupId>net.revelc.code</groupId> - <artifactId>impsort-maven-plugin</artifactId> - <version>${impsort-maven-plugin.version}</version> - <configuration> - <groups>java.,javax.,org.w3c.,org.xml.,junit.</groups> - <removeUnused>true</removeUnused> - <staticAfter>true</staticAfter> - <staticGroups>java.,javax.,org.w3c.,org.xml.,junit.</staticGroups> - </configuration> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>${maven-compiler-plugin.version}</version> - <configuration> - <showDeprecation>true</showDeprecation> - <showWarnings>true</showWarnings> - <compilerArgs> - <arg>-Xlint:unchecked</arg> - </compilerArgs> - </configuration> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <version>${maven-surefire-plugin.version}</version> - <configuration> - <failIfNoTests>false</failIfNoTests> - <systemProperties> - <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> - </systemProperties> - </configuration> - </plugin> - - <plugin> - <groupId>${quarkus.platform.group-id}</groupId> - <artifactId>quarkus-maven-plugin</artifactId> - <version>${quarkus.platform.version}</version> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-failsafe-plugin</artifactId> - <version>${maven-surefire-plugin.version}</version> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <version>${maven-jar-plugin.version}</version> - </plugin> - - <plugin> - <groupId>com.mycila</groupId> - <artifactId>license-maven-plugin</artifactId> - <version>${mycila-license.version}</version> - <configuration> - <failIfUnknown>true</failIfUnknown> - <header>${maven.multiModuleProjectDirectory}/header.txt</header> - <excludes> - <exclude>**/*.adoc</exclude> - <exclude>**/*.txt</exclude> - <exclude>**/LICENSE.txt</exclude> - <exclude>**/LICENSE</exclude> - <exclude>**/NOTICE.txt</exclude> - <exclude>**/NOTICE</exclude> - <exclude>**/README</exclude> - <exclude>**/pom.xml.versionsBackup</exclude> - </excludes> - <mapping> - <java>SLASHSTAR_STYLE</java> - <properties>CAMEL_PROPERTIES_STYLE</properties> - <kt>SLASHSTAR_STYLE</kt> - </mapping> - <headerDefinitions> - <headerDefinition>${maven.multiModuleProjectDirectory}/license-properties-headerdefinition.xml</headerDefinition> - </headerDefinitions> - </configuration> - </plugin> - </plugins> - </pluginManagement> - - <plugins> - <plugin> - <groupId>${quarkus.platform.group-id}</groupId> - <artifactId>quarkus-maven-plugin</artifactId> - <executions> - <execution> - <id>build</id> - <goals> - <goal>build</goal> - </goals> - </execution> - </executions> - </plugin> - - <plugin> - <groupId>net.revelc.code.formatter</groupId> - <artifactId>formatter-maven-plugin</artifactId> - <executions> - <execution> - <id>format</id> - <goals> - <goal>format</goal> - </goals> - <phase>process-sources</phase> - </execution> - </executions> - </plugin> - - <plugin> - <groupId>net.revelc.code</groupId> - <artifactId>impsort-maven-plugin</artifactId> - <executions> - <execution> - <id>sort-imports</id> - <goals> - <goal>sort</goal> - </goals> - <phase>process-sources</phase> - </execution> - </executions> - </plugin> - </plugins> - </build> - - <profiles> - <profile> - <id>native</id> - <activation> - <property> - <name>native</name> - </property> - </activation> - <properties> - <quarkus.package.type>native</quarkus.package.type> - </properties> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-failsafe-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>integration-test</goal> - <goal>verify</goal> - </goals> - <configuration> - <systemPropertyVariables> - <quarkus.package.type>${quarkus.package.type}</quarkus.package.type> - </systemPropertyVariables> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - </profile> - </profiles> - -</project> diff --git a/timer-log-spring/src/main/java/org/acme/spring/Counter.java b/timer-log-spring/src/main/java/org/acme/spring/Counter.java deleted file mode 100644 index 32c4077..0000000 --- a/timer-log-spring/src/main/java/org/acme/spring/Counter.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.acme.spring; - -import java.util.concurrent.atomic.AtomicInteger; - -import org.springframework.stereotype.Component; - -/** - * A counter bean. - */ -@Component -public class Counter { - private final AtomicInteger value = new AtomicInteger(0); - - public int increment() { - return value.incrementAndGet(); - } - - public int getValue() { - return value.get(); - } -} diff --git a/timer-log-spring/src/main/java/org/acme/spring/TimerRoute.java b/timer-log-spring/src/main/java/org/acme/spring/TimerRoute.java deleted file mode 100644 index 6604b61..0000000 --- a/timer-log-spring/src/main/java/org/acme/spring/TimerRoute.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.acme.spring; - -import org.apache.camel.builder.RouteBuilder; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; - -/** - * A {@link RouteBuilder} demonstrating the use of Spring Dependency Injection. - */ -@Service -public class TimerRoute extends RouteBuilder { - - /** - * {@code timer.period} is defined in {@code src/main/resources/application.properties} - */ - @Value("timer.period") - String period = "1000"; - - /** - * An injected bean - */ - @Autowired - Counter counter; - - @Override - public void configure() throws Exception { - fromF("timer:foo?period=%s", period) - .setBody(exchange -> "Incremented the counter: " + counter.increment()) - .to("log:example?showExchangePattern=false&showBodyType=false"); - } -} diff --git a/timer-log-spring/src/main/resources/application.properties b/timer-log-spring/src/main/resources/application.properties deleted file mode 100644 index 82f885a..0000000 --- a/timer-log-spring/src/main/resources/application.properties +++ /dev/null @@ -1,33 +0,0 @@ -## --------------------------------------------------------------------------- -## 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. -## --------------------------------------------------------------------------- - -# -# Quarkus -# -quarkus.banner.enabled = false -quarkus.log.file.enable = true - -# -# Camel -# -camel.context.name = quarkus-camel-example-timer-log-spring - -# -# Integration -# - -timer.period = 5000 \ No newline at end of file diff --git a/timer-log-spring/src/test/java/org/acme/spring/TimerLogSpringIT.java b/timer-log-spring/src/test/java/org/acme/spring/TimerLogSpringIT.java deleted file mode 100644 index b7358c3..0000000 --- a/timer-log-spring/src/test/java/org/acme/spring/TimerLogSpringIT.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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.acme.spring; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -class TimerLogSpringIT extends TimerLogSpringTest { - -} diff --git a/timer-log-spring/src/test/java/org/acme/spring/TimerLogSpringTest.java b/timer-log-spring/src/test/java/org/acme/spring/TimerLogSpringTest.java deleted file mode 100644 index b39510e..0000000 --- a/timer-log-spring/src/test/java/org/acme/spring/TimerLogSpringTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.acme.spring; - -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.concurrent.TimeUnit; - -import io.quarkus.test.junit.QuarkusTest; -import org.junit.jupiter.api.Test; - -import static org.awaitility.Awaitility.await; - -@QuarkusTest -public class TimerLogSpringTest { - - @Test - public void testTimerLogSpring() { - 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("Incremented the counter"); - }); - } -} diff --git a/timer-log-xml/README.adoc b/timer-log-xml/README.adoc deleted file mode 100644 index 55c21d9..0000000 --- a/timer-log-xml/README.adoc +++ /dev/null @@ -1,61 +0,0 @@ -= XML Hello World: A Camel Quarkus example -:cq-example-description: An example that shows how to define Camel routes using XML. - -{cq-description} - -TIP: Check the https://camel.apache.org/camel-quarkus/latest/first-steps.html[Camel Quarkus User guide] for prerequisites -and other general information. - -== Start in the Development mode - -[source,shell] ----- -$ mvn clean compile quarkus:dev ----- - -The above command compiles the project, starts the application and lets the Quarkus tooling watch for changes in your -workspace. Any modifications in your project will automatically take effect in the running application. - -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. 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 logging output to be `Bye XML`. - -=== Package and run the application - -Once you are done with developing you may want to package and run the application. - -TIP: Find more details about the JVM mode and Native mode in the Package and run section of -https://camel.apache.org/camel-quarkus/latest/first-steps.html#_package_and_run_the_application[Camel Quarkus User guide] - -==== JVM mode - -[source,shell] ----- -$ mvn clean package -$ java -jar target/quarkus-app/quarkus-run.jar -... -[io.quarkus] (main) camel-quarkus-examples-... started in 1.163s. ----- - -==== Native mode - -IMPORTANT: Native mode requires having GraalVM and other tools installed. Please check the Prerequisites section -of https://camel.apache.org/camel-quarkus/latest/first-steps.html#_prerequisites[Camel Quarkus User guide]. - -To prepare a native executable using GraalVM, run the following command: - -[source,shell] ----- -$ mvn clean package -Pnative -$ ./target/*-runner -... -[io.quarkus] (main) camel-quarkus-examples-... started in 0.013s. -... ----- - -== Feedback - -Please report bugs and propose improvements via https://github.com/apache/camel-quarkus/issues[GitHub issues of Camel Quarkus] project. diff --git a/timer-log-xml/pom.xml b/timer-log-xml/pom.xml deleted file mode 100644 index 8cbe426..0000000 --- a/timer-log-xml/pom.xml +++ /dev/null @@ -1,287 +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. - ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <artifactId>camel-quarkus-examples-timer-log-xml</artifactId> - <groupId>org.apache.camel.quarkus.examples</groupId> - <version>2.11.0-SNAPSHOT</version> - - <name>Camel Quarkus :: Examples :: Timer Log XML</name> - <description>Camel Quarkus Example :: Timer to Log XML</description> - - <properties> - <quarkus.platform.version>2.10.0.Final</quarkus.platform.version> - <camel-quarkus.platform.version>2.11.0-SNAPSHOT</camel-quarkus.platform.version> - - <quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id> - <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id> - <camel-quarkus.platform.group-id>org.apache.camel.quarkus</camel-quarkus.platform.group-id> - <camel-quarkus.platform.artifact-id>camel-quarkus-bom</camel-quarkus.platform.artifact-id> - - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> - <maven.compiler.target>11</maven.compiler.target> - <maven.compiler.source>11</maven.compiler.source> - <maven.compiler.testTarget>${maven.compiler.target}</maven.compiler.testTarget> - <maven.compiler.testSource>${maven.compiler.source}</maven.compiler.testSource> - - <formatter-maven-plugin.version>2.17.1</formatter-maven-plugin.version> - <impsort-maven-plugin.version>1.3.2</impsort-maven-plugin.version> - <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version> - <maven-jar-plugin.version>3.2.0</maven-jar-plugin.version> - <maven-resources-plugin.version>3.1.0</maven-resources-plugin.version> - <maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version> - <mycila-license.version>3.0</mycila-license.version> - </properties> - - <dependencyManagement> - <dependencies> - <!-- Import BOM --> - <dependency> - <groupId>${quarkus.platform.group-id}</groupId> - <artifactId>${quarkus.platform.artifact-id}</artifactId> - <version>${quarkus.platform.version}</version> - <type>pom</type> - <scope>import</scope> - </dependency> - <dependency> - <groupId>${camel-quarkus.platform.group-id}</groupId> - <artifactId>${camel-quarkus.platform.artifact-id}</artifactId> - <version>${camel-quarkus.platform.version}</version> - <type>pom</type> - <scope>import</scope> - </dependency> - </dependencies> - </dependencyManagement> - - <dependencies> - <dependency> - <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-log</artifactId> - </dependency> - <dependency> - <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-microprofile-health</artifactId> - </dependency> - <dependency> - <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-timer</artifactId> - </dependency> - <dependency> - <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-xml-io-dsl</artifactId> - </dependency> - - <!-- Test --> - <dependency> - <groupId>io.quarkus</groupId> - <artifactId>quarkus-junit5</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.awaitility</groupId> - <artifactId>awaitility</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <pluginManagement> - <plugins> - - <plugin> - <groupId>net.revelc.code.formatter</groupId> - <artifactId>formatter-maven-plugin</artifactId> - <version>${formatter-maven-plugin.version}</version> - <configuration> - <configFile>${maven.multiModuleProjectDirectory}/eclipse-formatter-config.xml</configFile> - <lineEnding>LF</lineEnding> - </configuration> - </plugin> - - <plugin> - <groupId>net.revelc.code</groupId> - <artifactId>impsort-maven-plugin</artifactId> - <version>${impsort-maven-plugin.version}</version> - <configuration> - <groups>java.,javax.,org.w3c.,org.xml.,junit.</groups> - <removeUnused>true</removeUnused> - <staticAfter>true</staticAfter> - <staticGroups>java.,javax.,org.w3c.,org.xml.,junit.</staticGroups> - </configuration> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>${maven-compiler-plugin.version}</version> - <configuration> - <showDeprecation>true</showDeprecation> - <showWarnings>true</showWarnings> - <compilerArgs> - <arg>-Xlint:unchecked</arg> - </compilerArgs> - </configuration> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <version>${maven-surefire-plugin.version}</version> - <configuration> - <failIfNoTests>false</failIfNoTests> - <systemProperties> - <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> - </systemProperties> - </configuration> - </plugin> - - <plugin> - <groupId>${quarkus.platform.group-id}</groupId> - <artifactId>quarkus-maven-plugin</artifactId> - <version>${quarkus.platform.version}</version> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-failsafe-plugin</artifactId> - <version>${maven-surefire-plugin.version}</version> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <version>${maven-jar-plugin.version}</version> - </plugin> - - <plugin> - <groupId>com.mycila</groupId> - <artifactId>license-maven-plugin</artifactId> - <version>${mycila-license.version}</version> - <configuration> - <failIfUnknown>true</failIfUnknown> - <header>${maven.multiModuleProjectDirectory}/header.txt</header> - <excludes> - <exclude>**/*.adoc</exclude> - <exclude>**/*.txt</exclude> - <exclude>**/LICENSE.txt</exclude> - <exclude>**/LICENSE</exclude> - <exclude>**/NOTICE.txt</exclude> - <exclude>**/NOTICE</exclude> - <exclude>**/README</exclude> - <exclude>**/pom.xml.versionsBackup</exclude> - </excludes> - <mapping> - <java>SLASHSTAR_STYLE</java> - <properties>CAMEL_PROPERTIES_STYLE</properties> - <kt>SLASHSTAR_STYLE</kt> - </mapping> - <headerDefinitions> - <headerDefinition>${maven.multiModuleProjectDirectory}/license-properties-headerdefinition.xml</headerDefinition> - </headerDefinitions> - </configuration> - </plugin> - </plugins> - </pluginManagement> - - <plugins> - <plugin> - <groupId>${quarkus.platform.group-id}</groupId> - <artifactId>quarkus-maven-plugin</artifactId> - <executions> - <execution> - <id>build</id> - <goals> - <goal>build</goal> - </goals> - </execution> - </executions> - <configuration> - <workingDir>${project.basedir}</workingDir> - </configuration> - </plugin> - - <plugin> - <groupId>net.revelc.code.formatter</groupId> - <artifactId>formatter-maven-plugin</artifactId> - <executions> - <execution> - <id>format</id> - <goals> - <goal>format</goal> - </goals> - <phase>process-sources</phase> - </execution> - </executions> - </plugin> - - <plugin> - <groupId>net.revelc.code</groupId> - <artifactId>impsort-maven-plugin</artifactId> - <executions> - <execution> - <id>sort-imports</id> - <goals> - <goal>sort</goal> - </goals> - <phase>process-sources</phase> - </execution> - </executions> - </plugin> - </plugins> - </build> - - <profiles> - <profile> - <id>native</id> - <activation> - <property> - <name>native</name> - </property> - </activation> - <properties> - <quarkus.package.type>native</quarkus.package.type> - </properties> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-failsafe-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>integration-test</goal> - <goal>verify</goal> - </goals> - <configuration> - <systemPropertyVariables> - <quarkus.package.type>${quarkus.package.type}</quarkus.package.type> - </systemPropertyVariables> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - </profile> - </profiles> - -</project> diff --git a/timer-log-xml/src/main/java/org/acme/xml/DummyClass.java b/timer-log-xml/src/main/java/org/acme/xml/DummyClass.java deleted file mode 100644 index 1a5f5b8..0000000 --- a/timer-log-xml/src/main/java/org/acme/xml/DummyClass.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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.acme.xml; - -public class DummyClass { -} diff --git a/timer-log-xml/src/main/java/org/acme/xml/package-info.java b/timer-log-xml/src/main/java/org/acme/xml/package-info.java deleted file mode 100644 index e28accf..0000000 --- a/timer-log-xml/src/main/java/org/acme/xml/package-info.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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.acme.xml; - -// Added to avoid quarkus-maven-plugin warning about empty source tree diff --git a/timer-log-xml/src/main/resources/application.properties b/timer-log-xml/src/main/resources/application.properties deleted file mode 100644 index 00bedd3..0000000 --- a/timer-log-xml/src/main/resources/application.properties +++ /dev/null @@ -1,34 +0,0 @@ -## --------------------------------------------------------------------------- -## 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. -## --------------------------------------------------------------------------- -# -# Quarkus -# -quarkus.banner.enabled = false -quarkus.log.file.enable = true - -# to turn on DEBUG logging in camel-main -# quarkus.log.category."org.apache.camel.main".level = DEBUG - -# -# Camel -# -camel.context.name = quarkus-camel-example-timer-log-xml - -# -# Camel Main -# -camel.main.routes-include-pattern= classpath:routes/my-routes.xml diff --git a/timer-log-xml/src/test/java/org/acme/xml/TimerLogXmlTest.java b/timer-log-xml/src/test/java/org/acme/xml/TimerLogXmlTest.java deleted file mode 100644 index 6f8949e..0000000 --- a/timer-log-xml/src/test/java/org/acme/xml/TimerLogXmlTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.acme.xml; - -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.concurrent.TimeUnit; - -import io.quarkus.test.junit.QuarkusTest; -import org.junit.jupiter.api.Test; - -import static org.awaitility.Awaitility.await; - -@QuarkusTest -public class TimerLogXmlTest { - - @Test - public void testTimerLogXml() { - 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("Hello XML!"); - }); - } - -} diff --git a/timer-log-xml/src/test/java/org/acme/xml/TimerLogXmlXmlIT.java b/timer-log-xml/src/test/java/org/acme/xml/TimerLogXmlXmlIT.java deleted file mode 100644 index 316cf49..0000000 --- a/timer-log-xml/src/test/java/org/acme/xml/TimerLogXmlXmlIT.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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.acme.xml; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -class TimerLogXmlXmlIT extends TimerLogXmlTest { - -} diff --git a/timer-log/README.adoc b/timer-log/README.adoc index bf1611a..3ec5203 100644 --- a/timer-log/README.adoc +++ b/timer-log/README.adoc @@ -19,9 +19,15 @@ workspace. Any modifications in your project will automatically take effect in t 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. 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 logging output to be `Bye World`. +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`. + +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`. + +The log message and the period at which the timer fires can be changed by modifying configuration properties `timer.period` and +`greeting.message` in `application.properties`. You can also override the default values via the command line with JVM arguments +`-Dtimer.period=5000 -Dgreeting.message="My Custom Greeting"` === Package and run the application diff --git a/timer-log/pom.xml b/timer-log/pom.xml index 888f048..05dbbb4 100644 --- a/timer-log/pom.xml +++ b/timer-log/pom.xml @@ -73,6 +73,14 @@ </dependencyManagement> <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-bean</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-log</artifactId> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-microprofile-health</artifactId> @@ -81,9 +89,11 @@ <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-timer</artifactId> </dependency> + + <!-- To demonstrate an XML route --> <dependency> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-log</artifactId> + <artifactId>camel-quarkus-xml-io-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 new file mode 100644 index 0000000..fb80d36 --- /dev/null +++ b/timer-log/src/main/java/org/acme/timer/log/ExchangeFormatterProducer.java @@ -0,0 +1,69 @@ +/* + * 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.acme.timer.log; + +import javax.enterprise.inject.Produces; + +import org.apache.camel.Exchange; +import org.apache.camel.component.log.LogComponent; +import org.apache.camel.spi.ExchangeFormatter; + +public class ExchangeFormatterProducer { + + /** + * Enum of ANSI escape codes for console colors. + */ + enum LogColor { + BLUE("\u001b[34m"), + YELLOW("\u001b[33m"); + + private String escapeCode; + + LogColor(String escapeCode) { + this.escapeCode = escapeCode; + } + + public String apply(String string) { + return this.escapeCode + string + "\u001b[0m"; + } + } + + /** + * Custom {@link ExchangeFormatter} bean to apply different colors to messages depending on which log endpoint they are + * sent to. + * + * This bean is automatically wired into the {@link LogComponent} on startup. + */ + @Produces + public ExchangeFormatter exchangeFormatter() { + return new ExchangeFormatter() { + @Override + public String format(Exchange exchange) { + String toEndpoint = exchange.getProperty(Exchange.TO_ENDPOINT, String.class); + String body = exchange.getMessage().getBody(String.class); + switch (toEndpoint) { + case "log://timer": + return LogColor.BLUE.apply("Java DSL: " + body); + case "log://timer-xml": + return LogColor.YELLOW.apply("XML DSL: " + body); + default: + return body; + } + } + }; + } +} diff --git a/timer-log-cdi/src/main/java/org/acme/cdi/Counter.java b/timer-log/src/main/java/org/acme/timer/log/GreetingBean.java similarity index 69% rename from timer-log-cdi/src/main/java/org/acme/cdi/Counter.java rename to timer-log/src/main/java/org/acme/timer/log/GreetingBean.java index 9759d6f..66dd48d 100644 --- a/timer-log-cdi/src/main/java/org/acme/cdi/Counter.java +++ b/timer-log/src/main/java/org/acme/timer/log/GreetingBean.java @@ -14,24 +14,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.acme.cdi; - -import java.util.concurrent.atomic.AtomicInteger; +package org.acme.timer.log; import javax.enterprise.context.ApplicationScoped; +import javax.inject.Named; + +import io.quarkus.runtime.annotations.RegisterForReflection; +import org.eclipse.microprofile.config.inject.ConfigProperty; -/** - * A counter bean. - */ @ApplicationScoped -public class Counter { - private final AtomicInteger value = new AtomicInteger(0); +@Named("greeting") +@RegisterForReflection(fields = false) +public class GreetingBean { - public int increment() { - return value.incrementAndGet(); - } + @ConfigProperty(name = "greeting.message") + String message; - public int getValue() { - return value.get(); + public String greet() { + return message; } } diff --git a/timer-log/src/main/java/org/acme/timer/log/TimerRoute.java b/timer-log/src/main/java/org/acme/timer/log/TimerRoute.java index 7dfd8c1..19f3a67 100644 --- a/timer-log/src/main/java/org/acme/timer/log/TimerRoute.java +++ b/timer-log/src/main/java/org/acme/timer/log/TimerRoute.java @@ -16,13 +16,17 @@ */ package org.acme.timer.log; +import javax.enterprise.context.ApplicationScoped; + import org.apache.camel.builder.RouteBuilder; +@ApplicationScoped public class TimerRoute extends RouteBuilder { @Override public void configure() throws Exception { - from("timer:foo?period=1000") - .log("Hello World"); + from("timer:foo?period={{timer.period}}") + .bean("greeting", "greet") + .to("log:timer"); } } diff --git a/timer-log/src/main/resources/application.properties b/timer-log/src/main/resources/application.properties index bac70c3..6ba528f 100644 --- a/timer-log/src/main/resources/application.properties +++ b/timer-log/src/main/resources/application.properties @@ -24,3 +24,8 @@ quarkus.log.file.enable = true # Camel # 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-xml/src/main/resources/routes/my-routes.xml b/timer-log/src/main/resources/routes/my-routes.xml similarity index 85% rename from timer-log-xml/src/main/resources/routes/my-routes.xml rename to timer-log/src/main/resources/routes/my-routes.xml index 75b8760..f1dff09 100644 --- a/timer-log-xml/src/main/resources/routes/my-routes.xml +++ b/timer-log/src/main/resources/routes/my-routes.xml @@ -24,8 +24,12 @@ https://camel.apache.org/schema/spring/camel-spring.xsd"> <route id="xml-route"> - <from uri="timer:from-xml?period=1000"/> - <log message="Hello XML!"/> + <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 52eba0d..90986c6 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 @@ -22,6 +22,8 @@ import java.nio.file.Paths; import java.util.concurrent.TimeUnit; import io.quarkus.test.junit.QuarkusTest; +import org.eclipse.microprofile.config.Config; +import org.eclipse.microprofile.config.ConfigProvider; import org.junit.jupiter.api.Test; import static org.awaitility.Awaitility.await; @@ -31,10 +33,12 @@ public class TimerLogTest { @Test public void testTimerLog() { + Config config = ConfigProvider.getConfig(); + 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("Hello World"); + return log.contains("Java DSL: " + greeting) && log.contains("XML DSL: " + greeting); }); } - }