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 07:43:17 UTC

[camel-kamelets-examples] branch main updated: Add languages example from camel-k

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 254e5a1  Add languages example from camel-k
254e5a1 is described below

commit 254e5a10c4c52e4a0d848a7a3cd429bfbc1c198e
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Aug 27 09:43:09 2022 +0200

    Add languages example from camel-k
---
 jbang/languages/README.adoc   | 91 +++++++++++++++++++++++++++++++++++++++++++
 jbang/languages/Sample.java   | 26 +++++++++++++
 jbang/languages/hello.xml     | 30 ++++++++++++++
 jbang/languages/routes.kts    | 23 +++++++++++
 jbang/languages/routes.yaml   | 27 +++++++++++++
 jbang/languages/simple.groovy | 23 +++++++++++
 jbang/languages/simple.js     | 21 ++++++++++
 7 files changed, 241 insertions(+)

diff --git a/jbang/languages/README.adoc b/jbang/languages/README.adoc
new file mode 100644
index 0000000..4d15304
--- /dev/null
+++ b/jbang/languages/README.adoc
@@ -0,0 +1,91 @@
+== Languages
+
+This example is demonstrating all the different DSLs supported by Apache Camel.
+
+Each DSL is a single hello world route in Java, YAML, XML, Groovy, Kotlin, JavaScript and so on.
+
+=== 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 *
+----
+
+You can also filter to only run the yaml DSL by:
+
+[source,sh]
+----
+$ jbang camel@apache/camel run *.yaml
+----
+
+=== 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 * --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/languages
+----
+
+=== Developer Web Console
+
+You can enable the developer console via `--console` flag as show:
+
+[source,sh]
+----
+$ camel run * --console
+----
+
+Then you can browse: http://localhost:8080/q/dev to introspect the running Camel applicaton.
+
+
+=== 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/languages/Sample.java b/jbang/languages/Sample.java
new file mode 100644
index 0000000..a8223ac
--- /dev/null
+++ b/jbang/languages/Sample.java
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class Sample extends RouteBuilder {
+  @Override
+  public void configure() throws Exception {
+	  from("timer:tick")
+        .log("Hello Camel K!");
+  }
+}
\ No newline at end of file
diff --git a/jbang/languages/hello.xml b/jbang/languages/hello.xml
new file mode 100644
index 0000000..75ae138
--- /dev/null
+++ b/jbang/languages/hello.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xmlns="http://camel.apache.org/schema/spring"
+        xsi:schemaLocation="
+            http://camel.apache.org/schema/spring
+            https://camel.apache.org/schema/spring/camel-spring.xsd">
+
+    <route id="hello">
+        <from uri="timer:hello?period=3000"/>
+        <setBody>
+            <constant>Hello World!!!</constant>
+        </setBody>
+        <to uri="log:info"/>
+    </route>
+
+</routes>
diff --git a/jbang/languages/routes.kts b/jbang/languages/routes.kts
new file mode 100755
index 0000000..713c91d
--- /dev/null
+++ b/jbang/languages/routes.kts
@@ -0,0 +1,23 @@
+// camel-k: language=kotlin
+/*
+ * 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.
+ */
+
+from("timer:kotlin?period=1000")
+  .routeId("kotlin")
+  .setBody()
+    .simple("Hello Camel K from \${routeId}")
+  .to("log:info")
diff --git a/jbang/languages/routes.yaml b/jbang/languages/routes.yaml
new file mode 100644
index 0000000..201b47a
--- /dev/null
+++ b/jbang/languages/routes.yaml
@@ -0,0 +1,27 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+
+- from:
+    uri: "timer:tick"
+    parameters:
+      period: "5000"
+    steps:
+      - set-body:
+          constant: "Hello Yaml !!!"
+      - transform:
+          simple: "${body.toUpperCase()}"
+      - to: "log:info"
diff --git a/jbang/languages/simple.groovy b/jbang/languages/simple.groovy
new file mode 100644
index 0000000..31ef570
--- /dev/null
+++ b/jbang/languages/simple.groovy
@@ -0,0 +1,23 @@
+// camel-k: language=groovy
+/*
+ * 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.
+ */
+
+from('timer:groovy?period=1000')
+    .routeId('groovy')
+    .setBody()
+        .simple('Hello Camel K from ${routeId}')
+    .to('log:info?showAll=false')
diff --git a/jbang/languages/simple.js b/jbang/languages/simple.js
new file mode 100644
index 0000000..ac0ad77
--- /dev/null
+++ b/jbang/languages/simple.js
@@ -0,0 +1,21 @@
+// camel-k: language=js
+// 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.
+
+from('timer:js?period=1000')
+    .routeId('js')
+    .setBody()
+        .simple('Hello Camel K from ${routeId}')
+    .to('log:info?multiline=true')