You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/11/13 16:43:59 UTC

[camel-quarkus] branch master updated: chore: add timer-log-cdi example

This is an automated email from the ASF dual-hosted git repository.

lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/master by this push:
     new 74ce46d  chore: add timer-log-cdi example
74ce46d is described below

commit 74ce46d8f1a7c833331a7f0749f6f5b6d59d17c2
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Wed Nov 13 11:58:42 2019 +0100

    chore: add timer-log-cdi example
---
 examples/pom.xml                                   |  3 +-
 examples/timer-log-cdi/README.adoc                 | 58 +++++++++++++
 examples/timer-log-cdi/pom.xml                     | 95 ++++++++++++++++++++++
 .../src/main/java/org/acme/timer/TimerRoute.java   | 35 ++++++++
 .../src/main/resources/application.properties      | 46 +++++++++++
 5 files changed, 236 insertions(+), 1 deletion(-)

diff --git a/examples/pom.xml b/examples/pom.xml
index 3e0b054..246e6f3 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -33,9 +33,10 @@
 
     <modules>
         <module>observability</module>
+        <module>rest-json</module>
         <module>timer-log</module>
+        <module>timer-log-cdi</module>
         <module>timer-log-xml</module>
-        <module>rest-json</module>
     </modules>
 
 </project>
diff --git a/examples/timer-log-cdi/README.adoc b/examples/timer-log-cdi/README.adoc
new file mode 100644
index 0000000..cfd1902
--- /dev/null
+++ b/examples/timer-log-cdi/README.adoc
@@ -0,0 +1,58 @@
+= timer-log
+
+This is a basic hello world example that uses CDI to set-up
+a Camel timer that triggers every second and prints to the
+log.
+
+TIP: Check the https://camel.apache.org/camel-quarkus/latest/user-guide.html[Camel Quarkus User guide] for prerequisites
+and other general information.
+
+== Start in the Development mode
+
+[source,shell]
+----
+$ mvn clean compile quarkus:dev -DnoDeps
+----
+
+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/user-guide.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` or 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/user-guide.html#_package_and_run_the_application[Camel Quarkus User guide]
+
+==== JVM mode
+
+[source,shell]
+----
+$ mvn clean package
+$ java -jar target/*-runner.jar
+...
+[io.quarkus] (main) Quarkus 0.23.2 started in 1.163s. Listening on: http://[::]:8080
+----
+
+==== 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/user-guide.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) Quarkus 0.23.2 started in 0.013s. Listening on: http://[::]:8080
+...
+----
diff --git a/examples/timer-log-cdi/pom.xml b/examples/timer-log-cdi/pom.xml
new file mode 100644
index 0000000..4689c54
--- /dev/null
+++ b/examples/timer-log-cdi/pom.xml
@@ -0,0 +1,95 @@
+<?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">
+    <parent>
+        <groupId>org.apache.camel.quarkus</groupId>
+        <artifactId>camel-quarkus-build-parent</artifactId>
+        <version>0.3.2-SNAPSHOT</version>
+        <relativePath>../../poms/build-parent/pom.xml</relativePath>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>camel-quarkus-examples-timer-log-cdi</artifactId>
+    <name>Camel Quarkus :: Examples :: Timer Log CDI</name>
+    <description>Camel Quarkus Example :: Timer to Log CDI</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-timer</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-log</artifactId>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>io.quarkus</groupId>
+                <artifactId>quarkus-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>build</id>
+                        <goals>
+                            <goal>build</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+    <profiles>
+        <profile>
+            <id>native</id>
+            <activation>
+                <property>
+                    <name>native</name>
+                </property>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>io.quarkus</groupId>
+                        <artifactId>quarkus-maven-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>native-image</id>
+                                <goals>
+                                    <goal>native-image</goal>
+                                </goals>
+                                <configuration>
+                                    <enableServer>false</enableServer>
+                                    <cleanupServer>true</cleanupServer>
+                                    <disableReports>true</disableReports>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+</project>
diff --git a/examples/timer-log-cdi/src/main/java/org/acme/timer/TimerRoute.java b/examples/timer-log-cdi/src/main/java/org/acme/timer/TimerRoute.java
new file mode 100644
index 0000000..5a1dc36
--- /dev/null
+++ b/examples/timer-log-cdi/src/main/java/org/acme/timer/TimerRoute.java
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+import javax.enterprise.context.ApplicationScoped;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.eclipse.microprofile.config.inject.ConfigProperty;
+
+@ApplicationScoped
+public class TimerRoute extends RouteBuilder {
+
+    @ConfigProperty(name = "timer.period", defaultValue = "1s")
+    String period;
+
+    @Override
+    public void configure() throws Exception {
+        fromF("timer:foo?period=%s", period)
+                .log("Hello World");
+    }
+}
diff --git a/examples/timer-log-cdi/src/main/resources/application.properties b/examples/timer-log-cdi/src/main/resources/application.properties
new file mode 100644
index 0000000..ce83d73
--- /dev/null
+++ b/examples/timer-log-cdi/src/main/resources/application.properties
@@ -0,0 +1,46 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements.  See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License.  You may obtain a copy of the License at
+##
+##      http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+#
+# Quarkus
+#
+quarkus.log.file.enable = false
+
+#
+# Quarkus - Camel
+#
+
+# disable build time route discovery as the only
+# route defined in this project is based on CDI.
+#
+# This is not strictly needed for the correctness
+# oc the example as camel-quarkus automatically
+# filters auto-discovered routes that targets CDI
+# but if is is known that routes are all leveraging
+# CDI, this option will give some little boost to
+# the build process
+quarkus.camel.main.routes-discovery.enabled = false
+
+#
+# Camel
+#
+camel.context.name = quarkus-camel-example-timer-log-cdi
+
+#
+# Integration
+#
+
+timer.period = 5s
\ No newline at end of file