You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gg...@apache.org on 2023/06/30 09:46:41 UTC
[camel-kamelets-examples] 02/02: Add example that registers bean instances from provided *.java file using XML and YAML DSLs
This is an automated email from the ASF dual-hosted git repository.
ggrzybek pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kamelets-examples.git
commit 8feb172a94a7868901c448e4ec86d6b20609fb10
Author: Grzegorz Grzybek <gr...@gmail.com>
AuthorDate: Fri Jun 30 11:46:27 2023 +0200
Add example that registers bean instances from provided *.java file using XML and YAML DSLs
---
jbang/app-routes-beans/README.adoc | 85 +++++++++++++++++++++++++++
jbang/app-routes-beans/StandaloneGreeter.java | 21 +++++++
jbang/app-routes-beans/app.xml | 29 +++++++++
jbang/app-routes-beans/beans.yaml | 5 ++
4 files changed, 140 insertions(+)
diff --git a/jbang/app-routes-beans/README.adoc b/jbang/app-routes-beans/README.adoc
new file mode 100644
index 0000000..6004eb9
--- /dev/null
+++ b/jbang/app-routes-beans/README.adoc
@@ -0,0 +1,85 @@
+== Hello Java
+
+This example shows how beans defined directly in Java source code can be added to Camel registry using XML and YAML DSLs.
+
+Camel 4 is required.
+
+=== 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 StandaloneGreeter.java beans.yaml app.xml
+----
+
+Or run with JBang using the longer command line (without installing camel as app in JBang):
+
+[source,sh]
+----
+$ jbang camel@apache/camel run StandaloneGreeter.java beans.yaml app.xml
+----
+
+=== Live reload
+
+You can run the example in dev mode which allows you to edit the example,
+and hot-reload when the file is saved.
+
+[source,sh]
+----
+$ camel run StandaloneGreeter.java beans.yaml app.xml --dev
+----
+
+=== Run directly from github
+
+The example can also be run directly by referring to the github URL as shown:
+
+[source,sh]
+----
+$ jbang camel@apache/camel run https://github.com/apache/camel-kamelets-examples/tree/main/jbang/app-routes-beans
+----
+
+=== Developer Web Console
+
+You can enable the developer console via `--console` flag as show:
+
+[source,sh]
+----
+$ camel run StandaloneGreeter.java beans.yaml app.xml --console
+----
+
+Then you can browse: http://localhost:8080/q/dev to introspect the running Camel applicaton.
+Under "beans" Camel should display `greeter1` and `greeter2` beans.
+
+
+=== 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/app-routes-beans/StandaloneGreeter.java b/jbang/app-routes-beans/StandaloneGreeter.java
new file mode 100644
index 0000000..2a43270
--- /dev/null
+++ b/jbang/app-routes-beans/StandaloneGreeter.java
@@ -0,0 +1,21 @@
+package camel.example;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.util.StringHelper;
+
+public class StandaloneGreeter implements Processor {
+
+ private String message;
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ String msg = exchange.getIn().getBody(String.class);
+ exchange.getIn().setBody(message + " " + StringHelper.after(msg, "I'm "));
+ }
+
+}
diff --git a/jbang/app-routes-beans/app.xml b/jbang/app-routes-beans/app.xml
new file mode 100644
index 0000000..ff245ca
--- /dev/null
+++ b/jbang/app-routes-beans/app.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<camel>
+
+ <bean name="greeter2" type="camel.example.StandaloneGreeter">
+ <properties>
+ <property key="message" value="Hello"/>
+ </properties>
+ </bean>
+
+ <route id="r1">
+ <from uri="timer:xml?period={{time:1100}}"/>
+ <setBody>
+ <simple>I'm Route ${routeId}</simple>
+ </setBody>
+ <bean ref="greeter1" />
+ <log message="${body}"/>
+ </route>
+
+ <route id="r2">
+ <from uri="timer:xml?period={{time:1200}}"/>
+ <setBody>
+ <simple>I'm Route ${routeId}</simple>
+ </setBody>
+ <bean ref="greeter2" />
+ <log message="${body}"/>
+ </route>
+
+</camel>
diff --git a/jbang/app-routes-beans/beans.yaml b/jbang/app-routes-beans/beans.yaml
new file mode 100644
index 0000000..150c587
--- /dev/null
+++ b/jbang/app-routes-beans/beans.yaml
@@ -0,0 +1,5 @@
+- beans:
+ - name: greeter1
+ type: camel.example.StandaloneGreeter
+ properties:
+ message: 'Howdy'