Skip to content

Commit

Permalink
Timer example (#312)
Browse files Browse the repository at this point in the history
* #310: A simple timer to log example as hello world

* #310: A simple timer to log example as hello world

* #310: Polished

* Update examples/timer-log/README.adoc

Co-Authored-By: Peter Palaga <ppalaga@redhat.com>
  • Loading branch information
davsclaus and ppalaga committed Oct 22, 2019
1 parent 876b52d commit 21544b2
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<name>Camel Quarkus :: Examples</name>

<modules>
<module>timer-log</module>
<module>rest-json</module>
</modules>

Expand Down
27 changes: 27 additions & 0 deletions examples/timer-log/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
= timer-log

This is a basic hello world example that uses a Camel timer that
triggers every second and prints to the log.

To run it:

[source,text]
----
$ mvn clean compile quarkus:dev -DnoDeps
----
This compiles the project and starts the Quarkus tooling in the https://quarkus.io/guides/maven-tooling#development-mode[develpment mode].
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`.

== Native build

To build as native:

[source,text]
----
$ mvn package -Pnative
----

This requires having GraalVM and other tools installed.
See the https://quarkus.io/guides/building-native-image-guide[Quarkus Native Guide] for details.
102 changes: 102 additions & 0 deletions examples/timer-log/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?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-bom</artifactId>
<version>0.2.1-SNAPSHOT</version>
<relativePath>../../poms/bom/pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>camel-quarkus-examples-timer-log</artifactId>
<name>Camel Quarkus :: Examples :: Timer Log</name>
<description>Camel Quarkus Example :: Timer to Log</description>

<properties>
<!-- to use docker build instead of native
<native-image.docker-build>true</native-image.docker-build>
<native-image.container-runtime>docker</native-image.container-runtime>
-->
</properties>

<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>
28 changes: 28 additions & 0 deletions examples/timer-log/src/main/java/org/acme/timer/TimerRoute.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 org.apache.camel.builder.RouteBuilder;

public class TimerRoute extends RouteBuilder {

@Override
public void configure() throws Exception {
from("timer:foo?period=1s")
.log("Hello World");
}
}
27 changes: 27 additions & 0 deletions examples/timer-log/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## ---------------------------------------------------------------------------
## 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.ssl.native=true

#
# Camel
#
camel.context.name = quarkus-camel-example-timer-log

0 comments on commit 21544b2

Please sign in to comment.