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 2023/12/04 17:23:46 UTC

(camel-kamelets-examples) branch main updated: CAMEL-20165: Add jbang 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 9898b13  CAMEL-20165: Add jbang example
9898b13 is described below

commit 9898b13f9ec1a2ebdf95d9b7685e708477864871
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Dec 4 18:23:35 2023 +0100

    CAMEL-20165: Add jbang example
---
 jbang/jbang-edit/README.adoc | 65 ++++++++++++++++++++++++++++++++++++++++++++
 jbang/jbang-edit/foo.java    | 31 +++++++++++++++++++++
 2 files changed, 96 insertions(+)

diff --git a/jbang/jbang-edit/README.adoc b/jbang/jbang-edit/README.adoc
new file mode 100644
index 0000000..a7830f0
--- /dev/null
+++ b/jbang/jbang-edit/README.adoc
@@ -0,0 +1,65 @@
+== JBang Edit
+
+This example shows how to use JBang to edit the source code by using the jbang CLI
+to download dependencies and setup project for being ready to load into an IDE of choice,
+such as IDEA, VSCode, or Eclipse.
+
+ === 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 foo.java
+----
+
+Or run with JBang using the longer command line (without installing camel as app in JBang):
+
+[source,sh]
+----
+$ jbang camel@apache/camel run foo.java
+----
+
+=== Editing source via jbang
+
+To make it easy to load the project into a Java editor such as IDEA or VSCode, then we can use jbang CLI for this.
+
+[source,sh]
+----
+$ jbang edit -b foo.java
+----
+
+JBang will then prepare for the project and ask you which IDE to use.
+
+
+=== 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!
diff --git a/jbang/jbang-edit/foo.java b/jbang/jbang-edit/foo.java
new file mode 100644
index 0000000..2ea5168
--- /dev/null
+++ b/jbang/jbang-edit/foo.java
@@ -0,0 +1,31 @@
+//DEPS org.apache.camel:camel-bom:4.3.0-SNAPSHOT@pom
+//DEPS org.apache.camel:camel-endpointdsl
+//DEPS org.apache.camel:camel-netty-http
+//DEPS org.apache.camel:camel-stream
+
+// add more dependencies here
+
+import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
+import org.apache.camel.component.netty.http.NettyHttpMessage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class foo extends EndpointRouteBuilder {
+
+    private static final Logger LOG = LoggerFactory.getLogger(foo.class);
+
+    @Override
+    public void configure() {
+        from(timer("trigger").period(5000).repeatCount(3))
+                .to(nettyHttp("https://random-data-api.com/api/v2/banks").keepAlive(true))
+                .process(e -> {
+                    // use classes from camel-netty-http dependency in the source code
+                    // and have jbang able to generate project with the dependencies ready
+                    // to use in your IDE of choice
+                    NettyHttpMessage msg = e.getMessage(NettyHttpMessage.class);
+                    LOG.info("Netty HTTP response:\n\n\n{}\n\n\n", msg.getHttpResponse());
+                })
+                .log("Found bank:")
+          .to(stream("out"));
+    }
+}
\ No newline at end of file