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/09 11:06:57 UTC

[camel-kamelets-examples] branch main updated (3ef1a4e -> 1f2bd21)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kamelets-examples.git


    from 3ef1a4e  Update ChaosMonkey.java
     new 5adf86d  Add http streaming example
     new 1f2bd21  Add to git ignore

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .gitignore                                         |  3 +-
 jbang/http-streaming/MyHttpServer.java             | 51 ++++++++++++++++++++++
 .../README.adoc                                    | 30 +++++--------
 jbang/http-streaming/my-stream.yaml                |  9 ++++
 4 files changed, 73 insertions(+), 20 deletions(-)
 create mode 100644 jbang/http-streaming/MyHttpServer.java
 copy jbang/{dependency-injection => http-streaming}/README.adoc (61%)
 create mode 100644 jbang/http-streaming/my-stream.yaml


[camel-kamelets-examples] 02/02: Add to git ignore

Posted by da...@apache.org.
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

commit 1f2bd21dee87dbb95c7009466d53950a78764058
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Aug 9 13:06:49 2022 +0200

    Add to git ignore
---
 .gitignore | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore
index 5639cf6..aa1bb21 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,5 @@ target/
 .camel-jbang/
 .vscode/
 .idea/
-camel-runner.jar
\ No newline at end of file
+camel-runner.jar
+*.i??
\ No newline at end of file


[camel-kamelets-examples] 01/02: Add http streaming example

Posted by da...@apache.org.
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

commit 5adf86d2ba7af0e904ff13a5d31d3d89567b0cbb
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Aug 9 13:06:11 2022 +0200

    Add http streaming example
---
 jbang/http-streaming/MyHttpServer.java | 51 ++++++++++++++++++++++++++++
 jbang/http-streaming/README.adoc       | 61 ++++++++++++++++++++++++++++++++++
 jbang/http-streaming/my-stream.yaml    |  9 +++++
 3 files changed, 121 insertions(+)

diff --git a/jbang/http-streaming/MyHttpServer.java b/jbang/http-streaming/MyHttpServer.java
new file mode 100644
index 0000000..4f4652e
--- /dev/null
+++ b/jbang/http-streaming/MyHttpServer.java
@@ -0,0 +1,51 @@
+/*
+ * 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 com.sun.net.httpserver.HttpContext;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpServer;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+
+public class MyHttpServer {
+
+  public static void main(String[] args) throws Exception {
+      HttpServer server = HttpServer.create(new InetSocketAddress(8500), 0);
+      HttpContext context = server.createContext("/");
+      context.setHandler(MyHttpServer::handleRequest);
+      System.out.println("http://localhost:8500");
+      server.start();
+  }
+
+  private static void handleRequest(HttpExchange exchange) throws IOException {
+      exchange.sendResponseHeaders(200, 0);
+      OutputStream os = exchange.getResponseBody();
+      for (int i = 0; i < 100; i++) {
+        String response = "Hello " + i + "\n";
+        os.write(response.getBytes());
+        os.flush();
+        System.out.println("... " + i);
+        try {
+          Thread.sleep(1000);
+        } catch (Exception e) {
+          // ignore
+        }
+      }
+      os.close();
+  }
+}
\ No newline at end of file
diff --git a/jbang/http-streaming/README.adoc b/jbang/http-streaming/README.adoc
new file mode 100644
index 0000000..36946c7
--- /dev/null
+++ b/jbang/http-streaming/README.adoc
@@ -0,0 +1,61 @@
+== HTTP Streaming
+
+This example shows how Camel can continuously read HTTP streaming data, from a remote HTTP server.
+The HTTP server is expected to send data back in chunks separated by new-line (HTTP streaming).
+
+=== 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
+
+You need to run the HTTP server first which can be done using Java:
+
+[source,sh]
+----
+$ java MyHttpServer.java
+----
+
+This starts a local HTTP server on port 8500
+
+Then you can run this example using:
+
+[source,sh]
+----
+$ camel run my-stream.yaml
+----
+
+Or run with JBang using the longer command line (without installing camel as app in JBang):
+
+[source,sh]
+----
+$ jbang camel@apache/camel run mystream.yaml
+----
+
+=== 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/http-streaming/my-stream.yaml b/jbang/http-streaming/my-stream.yaml
new file mode 100644
index 0000000..f1d17f8
--- /dev/null
+++ b/jbang/http-streaming/my-stream.yaml
@@ -0,0 +1,9 @@
+# camel-k: language=yaml
+
+- from:
+    uri: "stream:http"
+    parameters:
+      httpUrl: "http://localhost:8500"
+      scanStream: true
+    steps:
+      - log: "${body}"