This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-examples.git
commit 3cde715c0de6a7c0ef967f3ba9cc228a9bb56f42 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Mon May 25 11:42:12 2020 +0200 Add camel-example-basic --- examples/camel-example-basic/README.adoc | 45 ++++++++++ examples/camel-example-basic/pom.xml | 98 ++++++++++++++++++++++ .../org/apache/camel/example/basic/CamelBasic.java | 51 +++++++++++ .../src/main/resources/log4j2.properties | 23 +++++ examples/pom.xml | 1 + 5 files changed, 218 insertions(+) diff --git a/examples/camel-example-basic/README.adoc b/examples/camel-example-basic/README.adoc new file mode 100644 index 0000000..24495ea --- /dev/null +++ b/examples/camel-example-basic/README.adoc @@ -0,0 +1,45 @@ +== Camel Basic Example + +=== Introduction + +This is a very basic example that shows how to get started with Camel. + +This example shows you that Camel can be used in standalone mode +as a _public static void main_ application. + +The example has only 1 java file in the `CamelBasic.java` located in the src folder. +There is code comments explaining in more details. + +=== Build + +You will need to compile this example first: + +.... +mvn compile +.... + +=== Run + +To run the example type + +.... +mvn camel:run +.... + +The + +To stop the example hit ctrl+c + +You can also run the example from your editor such as Eclipse, IDEA etc, +by opening the org.apache.camel.example.basic.CamelBasic class +and then right click, and chose run java application. + +=== Help and contributions + +If you hit any problem using Camel or have some feedback, then please +https://camel.apache.org/support.html[let us know]. + +We also love contributors, so +https://camel.apache.org/contributing.html[get involved] :-) + +The Camel riders! diff --git a/examples/camel-example-basic/pom.xml b/examples/camel-example-basic/pom.xml new file mode 100644 index 0000000..dea9f92 --- /dev/null +++ b/examples/camel-example-basic/pom.xml @@ -0,0 +1,98 @@ +<?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/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel.example</groupId> + <artifactId>examples</artifactId> + <version>3.4.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-example-basic</artifactId> + <packaging>jar</packaging> + <name>Camel :: Example :: Basic</name> + <description>Basic example</description> + + <properties> + <category>Beginner</category> + </properties> + + <dependencyManagement> + <dependencies> + <!-- Add Camel BOM --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bom</artifactId> + <version>${camel.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core</artifactId> + </dependency> + + <!-- logging --> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + <scope>runtime</scope> + <version>${log4j2-version}</version> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <scope>runtime</scope> + <version>${log4j2-version}</version> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <scope>runtime</scope> + <version>${log4j2-version}</version> + </dependency> + + </dependencies> + + <build> + <plugins> + + <!-- Allows the routes to be run via 'mvn camel:run' --> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-maven-plugin</artifactId> + <version>${camel.version}</version> + <configuration> + <mainClass>org.apache.camel.example.basic.CamelBasic</mainClass> + </configuration> + </plugin> + + </plugins> + + </build> + +</project> diff --git a/examples/camel-example-basic/src/main/java/org/apache/camel/example/basic/CamelBasic.java b/examples/camel-example-basic/src/main/java/org/apache/camel/example/basic/CamelBasic.java new file mode 100644 index 0000000..528b9cd --- /dev/null +++ b/examples/camel-example-basic/src/main/java/org/apache/camel/example/basic/CamelBasic.java @@ -0,0 +1,51 @@ +/* + * 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.apache.camel.example.basic; + +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.DefaultCamelContext; + +/** + * A basic example running as public static void main. + */ +public final class CamelBasic { + + public static void main(String[] args) throws Exception { + // create a CamelContext + CamelContext camel = new DefaultCamelContext(); + + // add routes which can be inlined as anonymous inner class + // (to keep all code in a single java file for this basic example) + camel.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from("timer:foo") + .log("Hello Camel"); + } + }); + + // start is not blocking + camel.start(); + + // so run for 10 seconds + Thread.sleep(10_000); + + // and then stop nicely + camel.stop(); + } +} diff --git a/examples/camel-example-basic/src/main/resources/log4j2.properties b/examples/camel-example-basic/src/main/resources/log4j2.properties new file mode 100644 index 0000000..d9f0508 --- /dev/null +++ b/examples/camel-example-basic/src/main/resources/log4j2.properties @@ -0,0 +1,23 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +appender.out.type = Console +appender.out.name = out +appender.out.layout.type = PatternLayout +appender.out.layout.pattern = [%30.30t] %-30.30c{1} %-5p %m%n +rootLogger.level = INFO +rootLogger.appenderRef.out.ref = out diff --git a/examples/pom.xml b/examples/pom.xml index b3e2f22..55ed2d2 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -89,6 +89,7 @@ <module>camel-example-artemis-amqp-blueprint</module> <module>camel-example-artemis-large-messages</module> <module>camel-example-as2</module> + <module>camel-example-basic</module> <module>camel-example-billboard-aggr</module> <module>camel-example-bigxml-split</module> <module>camel-example-cafe</module>