You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2020/10/28 14:05:19 UTC

[camel-k] 02/02: doc(examples): timer source to log sink kamelet example

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

nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 9d5467a7d7504883f0c887ac7dc01d2d1d8aa173
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Fri Oct 23 16:32:25 2020 +0200

    doc(examples): timer source to log sink kamelet example
---
 .../timer-source-log-sink/log-sink.binding.yaml    | 32 +++++++++++
 .../timer-source-log-sink/log-sink.kamelet.yaml    | 34 ++++++++++++
 examples/kamelets/timer-source-log-sink/readme.md  | 62 ++++++++++++++++++++++
 .../timer-source-log-sink/timer-events.yaml        | 21 ++++++++
 .../timer-source.binding.yaml                      | 34 ++++++++++++
 .../timer-source.kamelet.yaml                      | 54 +++++++++++++++++++
 6 files changed, 237 insertions(+)

diff --git a/examples/kamelets/timer-source-log-sink/log-sink.binding.yaml b/examples/kamelets/timer-source-log-sink/log-sink.binding.yaml
new file mode 100644
index 0000000..6b6608c
--- /dev/null
+++ b/examples/kamelets/timer-source-log-sink/log-sink.binding.yaml
@@ -0,0 +1,32 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+
+apiVersion: camel.apache.org/v1alpha1
+kind: KameletBinding
+metadata:
+  name: log-event-sink
+spec:
+  source:
+    ref:
+      kind: InMemoryChannel
+      apiVersion: messaging.knative.dev/v1beta1
+      name: messages
+  sink:
+    ref:
+      kind: Kamelet
+      apiVersion: camel.apache.org/v1alpha1
+      name: log-sink
diff --git a/examples/kamelets/timer-source-log-sink/log-sink.kamelet.yaml b/examples/kamelets/timer-source-log-sink/log-sink.kamelet.yaml
new file mode 100644
index 0000000..0d9ff42
--- /dev/null
+++ b/examples/kamelets/timer-source-log-sink/log-sink.kamelet.yaml
@@ -0,0 +1,34 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+
+apiVersion: camel.apache.org/v1alpha1
+kind: Kamelet
+metadata:
+  name: log-sink
+  annotations:
+    camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEwAACxMBAJqcGAAACcBJREFUeJzt3XmsHVUdwPHva21poWGTUpAiVRQSFjWAyi5LcCmKLCEouLwQccMgGsISEkQRXMIfSKMGhQSMCCibkRIgghQEF4RIQYtG4YFsraRlb6G+1j9+94a50/fmvuW+OTN3vp9kkrnnzj3zu+/N786ZmTNnQJIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZKkfjOQOoAKGQA+DJwAvBfYCpieNKKJexk4E/h56kDUH94O3AOs76NpHfDlXv6R1Ey7ACtIv0FP1XRa7/5Uapo5wL9JvxFP9fSNXv3Bmu [...]
+  labels:
+    camel.apache.org/kamelet.type: "sink"
+spec:
+  definition:
+    title: "Log Sink"
+    description: "Consume events from a channel"
+  flow:
+    from:
+      uri: kamelet:source
+      steps:
+      - to: "log:sink"
diff --git a/examples/kamelets/timer-source-log-sink/readme.md b/examples/kamelets/timer-source-log-sink/readme.md
new file mode 100644
index 0000000..4d4d671
--- /dev/null
+++ b/examples/kamelets/timer-source-log-sink/readme.md
@@ -0,0 +1,62 @@
+# Timer Source to Log Sink
+
+This example shows how to create a simple timer `event source` and a log `event sink`. The timer events emitted are consumed by a simple logging connector which will print out those events.
+
+## Create events source and sink
+
+Let's start by creating the timer event source and log event sink as `kamelet`s.
+```
+$ kubectl apply -f timer-source.kamelet.yaml
+$ kubectl apply -f log-sink.kamelet.yaml
+```
+
+You can check the newly created `kamelet`s in the list.
+```
+$ kubectl get kamelets
+
+NAME           PHASE
+log-sink       Ready
+timer-source   Ready
+```
+
+## Create channel destination
+
+Let's continue by creating a `knative` destination.
+```
+$ kubectl apply -f timer-events.yaml
+```
+
+## Binding events
+
+We can now bind the timer event source to produce events on the destination with the `timer-source.binding.yaml` configuration.
+```
+$ kubectl apply -f timer-source.binding.yaml
+```
+In a similar fashion you can bind to the log sink in order to consume those events with the `log-sink.binding.yaml` configuration.
+```
+$ kubectl apply -f log-sink.binding.yaml
+```
+You can check the newly created bindings listing the `KameletBidings`.
+```
+$ kubectl get KameletBindings
+
+NAME                 PHASE
+log-event-sink       Ready
+timer-event-source   Ready
+```
+
+### Watch the event sink
+
+After a while you will be able to watch the event consumed by the underlying `log-event-sink` integration:
+
+```
+$ kamel log log-event-sink
+
+[1] Monitoring pod log-event-sink-wjm9w-deployment-cf4f49655-xwq82
+...
+[1] 2020-10-23 14:28:11,878 INFO  [sink] (vert.x-worker-thread-1) Exchange[ExchangePattern: InOnly, BodyType: byte[], Body: Hello world!]
+[1] 2020-10-23 14:28:11,877 INFO  [sink] (vert.x-worker-thread-0) Exchange[ExchangePattern: InOnly, BodyType: byte[], Body: Hello world!]
+[1] 2020-10-23 14:28:12,381 INFO  [sink] (vert.x-worker-thread-2) Exchange[ExchangePattern: InOnly, BodyType: byte[], Body: Hello world!]
+[1] 2020-10-23 14:28:13,276 INFO  [sink] (vert.x-worker-thread-3) Exchange[ExchangePattern: InOnly, BodyType: byte[], Body: Hello world!]
+[1] 2020-10-23 14:28:14,299 INFO  [sink] (vert.x-worker-thread-4) Exchange[ExchangePattern: InOnly, BodyType: byte[], Body: Hello world!]
+```
\ No newline at end of file
diff --git a/examples/kamelets/timer-source-log-sink/timer-events.yaml b/examples/kamelets/timer-source-log-sink/timer-events.yaml
new file mode 100644
index 0000000..b7b4133
--- /dev/null
+++ b/examples/kamelets/timer-source-log-sink/timer-events.yaml
@@ -0,0 +1,21 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+
+apiVersion: messaging.knative.dev/v1beta1
+kind: InMemoryChannel
+metadata:
+  name: messages
\ No newline at end of file
diff --git a/examples/kamelets/timer-source-log-sink/timer-source.binding.yaml b/examples/kamelets/timer-source-log-sink/timer-source.binding.yaml
new file mode 100644
index 0000000..622e015
--- /dev/null
+++ b/examples/kamelets/timer-source-log-sink/timer-source.binding.yaml
@@ -0,0 +1,34 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+
+apiVersion: camel.apache.org/v1alpha1
+kind: KameletBinding
+metadata:
+  name: timer-event-source
+spec:
+  source:
+    ref:
+      kind: Kamelet
+      apiVersion: camel.apache.org/v1alpha1
+      name: timer-source
+    properties:
+      message: "Hello world!"
+  sink:
+    ref:
+      kind: InMemoryChannel
+      apiVersion: messaging.knative.dev/v1beta1
+      name: messages
\ No newline at end of file
diff --git a/examples/kamelets/timer-source-log-sink/timer-source.kamelet.yaml b/examples/kamelets/timer-source-log-sink/timer-source.kamelet.yaml
new file mode 100644
index 0000000..47a6393
--- /dev/null
+++ b/examples/kamelets/timer-source-log-sink/timer-source.kamelet.yaml
@@ -0,0 +1,54 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+
+apiVersion: camel.apache.org/v1alpha1
+kind: Kamelet
+metadata:
+  name: timer-source
+  annotations:
+    camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gU3ZnIFZlY3RvciBJY29ucyA6IGh0dHA6Ly93d3cub25saW5ld2ViZm9udHMuY29tL2ljb24gLS0+DQo8IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPg0KPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm [...]
+  labels:
+    camel.apache.org/kamelet.type: "source"
+spec:
+  definition:
+    title: "Timer Source"
+    description: "Produces periodic events with a custom payload"
+    required:
+      - message
+    properties:
+      period:
+        title: Period
+        description: The interval between two events
+        type: integer
+        default: 1000
+      message:
+        title: Message
+        description: The message to generate
+        type: string
+        example: "hello world"
+  types:
+    out:
+      mediaType: text/plain
+  flow:
+    from:
+      uri: timer:tick
+      parameters:
+        period: "#property:period"
+      steps:
+      - set-body:
+          constant: "{{message}}"
+      - to: "kamelet:sink"
\ No newline at end of file