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/30 15:17:55 UTC

(camel-kamelets-examples) branch main updated: CAMEL-19749: Add variables as concept to Camel

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 1579ece  CAMEL-19749: Add variables as concept to Camel
1579ece is described below

commit 1579ece5969e7254fea15c833042b4d17f85466a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Dec 30 14:23:00 2023 +0100

    CAMEL-19749: Add variables as concept to Camel
---
 jbang/variables/README.adoc | 59 +++++++++++++++++++++++++++++++++++++++++++++
 jbang/variables/myapp.java  | 18 ++++++++++++++
 2 files changed, 77 insertions(+)

diff --git a/jbang/variables/README.adoc b/jbang/variables/README.adoc
new file mode 100644
index 0000000..263a07d
--- /dev/null
+++ b/jbang/variables/README.adoc
@@ -0,0 +1,59 @@
+== Variables
+
+This example shows how you can use global variables with Camel routes.
+
+=== 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 myapp.java
+----
+
+Or run with wildcard:
+
+[source,sh]
+----
+$ camel run *
+----
+
+You can list the variables from the CLI by executing:
+
+[source,sh]
+----
+$ camel get variable
+----
+
+
+=== 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/variables/myapp.java b/jbang/variables/myapp.java
new file mode 100644
index 0000000..6f684e8
--- /dev/null
+++ b/jbang/variables/myapp.java
@@ -0,0 +1,18 @@
+// camel-k: language=java
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class myapp extends RouteBuilder {
+
+    @Override
+    public void configure() throws Exception {
+        from("timer:java")
+            .setVariable("global:app", simple("${camelId}"))
+            .setVariable("global:random", simple("${random(1,10)}"));
+
+        from("timer:random?period={{time:1000}}")
+            .setBody(simple("Random number: ${variable.global:random}"))
+            .log("${body}");
+
+    }
+}