You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/08/27 05:46:00 UTC

[camel-examples] branch main updated: Make example simpler and work with Camel CLI

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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-examples.git


The following commit(s) were added to refs/heads/main by this push:
     new 7ed59a7e Make example simpler and work with Camel CLI
7ed59a7e is described below

commit 7ed59a7eebb313505d0a939d59e43e3d77a3cbaf
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Aug 27 07:45:46 2022 +0200

    Make example simpler and work with Camel CLI
---
 examples/main/README.adoc                              | 14 ++++++++++++++
 examples/main/pom.xml                                  |  8 +++++++-
 examples/main/src/main/data/foo.properties             | 18 ------------------
 .../src/main/java/org/apache/camel/example/MyBean.java |  7 +------
 .../java/org/apache/camel/example/MyConfiguration.java |  4 ++--
 .../java/org/apache/camel/example/MyRouteBuilder.java  |  4 +---
 .../java/org/apache/camel/example/StandaloneCamel.java |  2 +-
 .../main/src/main/resources/application.properties     | 15 ++-------------
 .../test/java/org/apache/camel/example/MainTest.java   |  2 +-
 .../apache/camel/example/MainWithAnnotationTest.java   |  2 +-
 10 files changed, 30 insertions(+), 46 deletions(-)

diff --git a/examples/main/README.adoc b/examples/main/README.adoc
index 165c6b17..3036c447 100644
--- a/examples/main/README.adoc
+++ b/examples/main/README.adoc
@@ -32,6 +32,20 @@ Then you can run this example using
 $ mvn camel:run
 ----
 
+=== Camel CLI
+
+This application is integrated with the Camel CLI via the `camel-cli-connector-starter` dependency (see `pom.xml`).
+This allows to use the Camel CLI to manage this application, such as:
+
+    $mvn package camel:run
+
+And then use the CLI to see status:
+
+    $camel get
+      PID   NAME                          CAMEL            PLATFORM  READY  STATUS   AGE  TOTAL  FAILED  INFLIGHT  SINCE-LAST
+     90491  org.apache.camel.example.My…  3.19.0-SNAPSHOT  Camel      1/1   Running  20s     11       0         0          0s
+
+
 === How to configure for Camel Textual Route debugging
 
 Several IDEs are providing support for Camel Textual Route debugging. To enable this possibility, you need to launch this example with the profile `camel.debug`.
diff --git a/examples/main/pom.xml b/examples/main/pom.xml
index f015f5ac..47f6ef13 100644
--- a/examples/main/pom.xml
+++ b/examples/main/pom.xml
@@ -61,7 +61,13 @@
         </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
-            <artifactId>camel-quartz</artifactId>
+            <artifactId>camel-timer</artifactId>
+        </dependency>
+
+        <!-- camel-cli -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-cli-connector</artifactId>
         </dependency>
 
         <!-- logging -->
diff --git a/examples/main/src/main/data/foo.properties b/examples/main/src/main/data/foo.properties
deleted file mode 100644
index b43e6bc0..00000000
--- a/examples/main/src/main/data/foo.properties
+++ /dev/null
@@ -1,18 +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.
-## ---------------------------------------------------------------------------
-
-bye = Bye
\ No newline at end of file
diff --git a/examples/main/src/main/java/org/apache/camel/example/MyBean.java b/examples/main/src/main/java/org/apache/camel/example/MyBean.java
index 1e1bdb85..7ee3da80 100644
--- a/examples/main/src/main/java/org/apache/camel/example/MyBean.java
+++ b/examples/main/src/main/java/org/apache/camel/example/MyBean.java
@@ -19,18 +19,13 @@ package org.apache.camel.example;
 public class MyBean {
 
     private String hi;
-    private String bye;
 
-    public MyBean(String hi, String bye) {
+    public MyBean(String hi) {
         this.hi = hi;
-        this.bye = bye;
     }
 
     public String hello() {
         return hi + " how are you?";
     }
 
-    public String bye() {
-        return bye + " World";
-    }
 }
diff --git a/examples/main/src/main/java/org/apache/camel/example/MyConfiguration.java b/examples/main/src/main/java/org/apache/camel/example/MyConfiguration.java
index c580e6b0..1a526628 100644
--- a/examples/main/src/main/java/org/apache/camel/example/MyConfiguration.java
+++ b/examples/main/src/main/java/org/apache/camel/example/MyConfiguration.java
@@ -27,9 +27,9 @@ import org.apache.camel.PropertyInject;
 public class MyConfiguration {
 
     @BindToRegistry
-    public MyBean myBean(@PropertyInject("hi") String hi, @PropertyInject("bye") String bye) {
+    public MyBean myBean(@PropertyInject("hi") String hi) {
         // this will create an instance of this bean with the name of the method (eg myBean)
-        return new MyBean(hi, bye);
+        return new MyBean(hi);
     }
 
 }
diff --git a/examples/main/src/main/java/org/apache/camel/example/MyRouteBuilder.java b/examples/main/src/main/java/org/apache/camel/example/MyRouteBuilder.java
index 06788dff..d38a4c1c 100644
--- a/examples/main/src/main/java/org/apache/camel/example/MyRouteBuilder.java
+++ b/examples/main/src/main/java/org/apache/camel/example/MyRouteBuilder.java
@@ -22,10 +22,8 @@ public class MyRouteBuilder extends RouteBuilder {
 
     @Override
     public void configure() throws Exception {
-        from("quartz:foo?cron={{myCron}}").routeId("foo")
+        from("timer:foo").routeId("foo")
             .bean("myBean", "hello")
-            .log("${body}")
-            .bean("myBean", "bye")
             .log("${body}");
     }
 }
diff --git a/examples/main/src/main/java/org/apache/camel/example/StandaloneCamel.java b/examples/main/src/main/java/org/apache/camel/example/StandaloneCamel.java
index 5ecbf129..c3b7c627 100644
--- a/examples/main/src/main/java/org/apache/camel/example/StandaloneCamel.java
+++ b/examples/main/src/main/java/org/apache/camel/example/StandaloneCamel.java
@@ -42,7 +42,7 @@ public final class StandaloneCamel {
             String hello = camelContext.resolvePropertyPlaceholders("{{hi}}");
 
             // and create bean with the placeholder
-            MyBean myBean = new MyBean(hello, "Bye");
+            MyBean myBean = new MyBean(hello);
             // register bean to Camel
             camelContext.getRegistry().bind("myBean", myBean);
 
diff --git a/examples/main/src/main/resources/application.properties b/examples/main/src/main/resources/application.properties
index 531e8797..e7493858 100644
--- a/examples/main/src/main/resources/application.properties
+++ b/examples/main/src/main/resources/application.properties
@@ -19,19 +19,8 @@
 # https://camel.apache.org/components/next/others/main.html
 camel.main.name = MyCoolCamel
 
-# enable tracing
-# camel.main.tracing = true
-# configure tracing what to include from the exchange
-#camel.context.tracer.exchange-formatter.show-exchange-id = false
-#camel.context.tracer.exchange-formatter.show-headers = true
-#camel.context.tracer.exchange-formatter.show-body-type = false
-
-# load additional property placeholders from this folder
-camel.main.file-configurations=src/main/data/*.properties
-
-# properties used in the route
-myCron = 0/2 * * * * ?
+# allows source:line precise logging
+camel.main.sourceLocationEnabled=true
 
 # application properties
 hi = Hello
-bye = Bye
diff --git a/examples/main/src/test/java/org/apache/camel/example/MainTest.java b/examples/main/src/test/java/org/apache/camel/example/MainTest.java
index 8b037bf5..43944f99 100644
--- a/examples/main/src/test/java/org/apache/camel/example/MainTest.java
+++ b/examples/main/src/test/java/org/apache/camel/example/MainTest.java
@@ -32,7 +32,7 @@ class MainTest extends CamelMainTestSupport {
     @Test
     void should_support_binding_via_annotations() {
         NotifyBuilder notify = new NotifyBuilder(context)
-            .whenCompleted(1).whenBodiesDone("Bye World").create();
+            .whenCompleted(1).whenBodiesDone("Hello how are you?").create();
         assertTrue(
             notify.matches(20, TimeUnit.SECONDS), "1 message should be completed"
         );
diff --git a/examples/main/src/test/java/org/apache/camel/example/MainWithAnnotationTest.java b/examples/main/src/test/java/org/apache/camel/example/MainWithAnnotationTest.java
index f0776162..f2cfbbfe 100644
--- a/examples/main/src/test/java/org/apache/camel/example/MainWithAnnotationTest.java
+++ b/examples/main/src/test/java/org/apache/camel/example/MainWithAnnotationTest.java
@@ -38,7 +38,7 @@ class MainWithAnnotationTest {
     @Test
     void should_support_binding_via_annotations() {
         NotifyBuilder notify = new NotifyBuilder(context)
-            .whenCompleted(1).whenBodiesDone("Bye World").create();
+            .whenCompleted(1).whenBodiesDone("Hello how are you?").create();
         assertTrue(
             notify.matches(20, TimeUnit.SECONDS), "1 message should be completed"
         );