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.git


The following commit(s) were added to refs/heads/master by this push:
     new 6279250  AAdd psvm class to run Camel standalone to this example.
6279250 is described below

commit 6279250702d9dac54988204d02a2d2c026470bb2
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Tue Mar 26 17:32:53 2019 +0100

    AAdd psvm class to run Camel standalone to this example.
---
 examples/camel-example-main/readme.adoc            |  7 +++
 .../org/apache/camel/example/StandaloneCamel.java  | 59 ++++++++++++++++++++++
 2 files changed, 66 insertions(+)

diff --git a/examples/camel-example-main/readme.adoc 
b/examples/camel-example-main/readme.adoc
index 3fe972c..03d224f 100644
--- a/examples/camel-example-main/readme.adoc
+++ b/examples/camel-example-main/readme.adoc
@@ -7,6 +7,13 @@ via Camel built-in dependency-injection that supports binding 
via the
 
 Also notice how you can configure Camel in the `application.properties` file.
 
+==== Alternative example
+
+The class `StandaloneCamel` is an alternative example that uses a
+_public static void main_ class and where you manually setup Camel without
+any help from Camel's built-in Main class. However it shows how to do this
+in a _raw style_ without using any _magic_.
+
 === How to run
 
 You can run this example using
diff --git 
a/examples/camel-example-main/src/main/java/org/apache/camel/example/StandaloneCamel.java
 
b/examples/camel-example-main/src/main/java/org/apache/camel/example/StandaloneCamel.java
new file mode 100644
index 0000000..c7c9889
--- /dev/null
+++ 
b/examples/camel-example-main/src/main/java/org/apache/camel/example/StandaloneCamel.java
@@ -0,0 +1,59 @@
+/*
+ * 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;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+
+/**
+ * This is an alternative example to show how you can use a public static void 
main class
+ * to run Camel standalone (without help from its Main class). This is to 
demonstrate
+ * what code you need to write to startup Camel without any help (or magic).
+ * <p/>
+ * Compare this example with {@link MyApplication} which uses Camel's main 
class to
+ * run Camel standalone in a easier way.
+ */
+public class StandaloneCamel {
+
+    public static void main(String[] args) throws Exception {
+        // create a new CamelContext
+        CamelContext camelContext = new DefaultCamelContext();
+
+        // configure where to load properties file in the properties component
+        
camelContext.getPropertiesComponent().setLocation("classpath:application.properties");
+        // resolve property placeholder
+        String hello = camelContext.resolvePropertyPlaceholders("{{hi}}");
+
+        // and create bean with the placeholder
+        MyBean myBean = new MyBean(hello);
+        // register bean to Camel
+        camelContext.getRegistry().bind("myBean", myBean);
+
+        // add routes to Camel
+        camelContext.addRoutes(new MyRouteBuilder());
+
+        // start Camel
+        camelContext.start();
+
+        // just run for 10 seconds and stop
+        System.out.println("Running for 10 seconds and then stopping");
+        Thread.sleep(10000);
+
+        // stop and shutdown Camel
+        camelContext.stop();
+    }
+}

Reply via email to