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/03/14 11:11:15 UTC

[camel-kamelets-examples] branch main updated: CAMEL-17571: Added example

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


The following commit(s) were added to refs/heads/main by this push:
     new 46042ed  CAMEL-17571: Added example
46042ed is described below

commit 46042ed73b00e724f0bd1489c90ed9a76a0feb09
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Mar 14 12:11:05 2022 +0100

    CAMEL-17571: Added example
---
 jbang/dependency-injection/Echo.java   | 25 ++++++++++++
 jbang/dependency-injection/Hello.java  | 19 +++++++++
 jbang/dependency-injection/README.adoc | 70 ++++++++++++++++++++++++++++++++++
 3 files changed, 114 insertions(+)

diff --git a/jbang/dependency-injection/Echo.java b/jbang/dependency-injection/Echo.java
new file mode 100755
index 0000000..22eb915
--- /dev/null
+++ b/jbang/dependency-injection/Echo.java
@@ -0,0 +1,25 @@
+// camel-k: language=java
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.stereotype.Component;
+
+import org.apache.camel.spi.CamelLogger;
+
+@Component("myEcho")
+public class Echo {
+
+  @Autowired
+  private org.apache.camel.CamelContext context;
+
+  @Bean
+  public CamelLogger myLogger() {
+    return new CamelLogger("myLogger");
+  }
+
+  public String echo(String echo) {
+    return echo + echo + "!! from " + context.getName();
+  }
+
+
+}
diff --git a/jbang/dependency-injection/Hello.java b/jbang/dependency-injection/Hello.java
new file mode 100755
index 0000000..77ecc62
--- /dev/null
+++ b/jbang/dependency-injection/Hello.java
@@ -0,0 +1,19 @@
+// camel-k: language=java
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class Hello extends RouteBuilder {
+
+  @Override
+  public void configure() throws Exception {
+
+      // Write your routes here, for example:
+      from("timer:java?period=1000")
+        .routeId("java")
+        .process(e -> {
+           e.getMessage().setBody("SpringBoot");
+        })
+        .bean("myEcho", "echo")
+        .bean("myLogger", "log(${body})");
+  }
+}
diff --git a/jbang/dependency-injection/README.adoc b/jbang/dependency-injection/README.adoc
new file mode 100644
index 0000000..ef5f569
--- /dev/null
+++ b/jbang/dependency-injection/README.adoc
@@ -0,0 +1,70 @@
+== Dependency Injection
+
+This example shows how Camel JBang can use dependency injection annotations
+from Spring Boot or Quarkus, to wire up Java beans.
+
+The runtime is still plain Camel Main with JBang, and not Spring Boot or Quarkus.
+However the benefit of allowing to use their annotations is that the transition
+from Camel JBang to Spring Boot or Quarkus is easier.
+
+
+=== Install JBang
+
+First install JBang according to https://www.jbang.dev
+
+When JBang is installed then you should be able to run from a shell:
+
+[source,sh]
+----
+$ jbang --version
+----
+
+This will output the version of JBang.
+
+To run this example you can either install Camel on JBang via:
+
+[source,sh]
+----
+$ jbang app install camel@apache/camel
+----
+
+Which allows to run CamelJBang with `camel` as shown below.
+
+=== How to run
+
+Then you can run this example using:
+
+[source,sh]
+----
+$ camel run *
+----
+
+Or run with JBang using the longer command line (without installing camel as app in JBang):
+
+[source,sh]
+----
+$ jbang camel@apache/camel run *
+----
+
+
+=== Live reload
+
+You can run the example with reload enabled which allows you to edit the example,
+and hot-reload when the file is saved.
+
+[source,sh]
+----
+$ camel run * --reload
+----
+
+
+
+=== Help and contributions
+
+If you hit any problem using Camel or have some feedback, then please
+https://camel.apache.org/community/support/[let us know].
+
+We also love contributors, so
+https://camel.apache.org/community/contributing/[get involved] :-)
+
+The Camel riders!