This is an automated email from the ASF dual-hosted git repository. astefanutti pushed a commit to branch release-1.4.x in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 9cdb435c3022fff8829c443f4764bb6ac26a4ca5 Author: Pasquale Congiusti <pasquale.congiu...@gmail.com> AuthorDate: Tue Mar 16 16:18:52 2021 +0100 doc(example): kameletbinding error handler --- .../kamelets/error-handler/error-sink.kamelet.yaml | 44 ++++++++++++++++++ .../kamelet-binding-error-handler.yaml | 38 +++++++++++++++ examples/kamelets/error-handler/readme.md | 49 ++++++++++++++++++++ .../error-handler/timer-source.kamelet.yaml | 54 ++++++++++++++++++++++ 4 files changed, 185 insertions(+) diff --git a/examples/kamelets/error-handler/error-sink.kamelet.yaml b/examples/kamelets/error-handler/error-sink.kamelet.yaml new file mode 100644 index 0000000..e35a54d --- /dev/null +++ b/examples/kamelets/error-handler/error-sink.kamelet.yaml @@ -0,0 +1,44 @@ +# --------------------------------------------------------------------------- +# 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: error-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: "Error Log Sink" + description: "Consume events from a channel" + required: + - defaultMessage + properties: + defaultMessage: + title: Message + description: The default message to log + type: string + example: "error while checking the source" + flow: + from: + uri: kamelet:source + steps: + - set-body: + constant: "{{defaultMessage}}" + - to: "log:error-sink" diff --git a/examples/kamelets/error-handler/kamelet-binding-error-handler.yaml b/examples/kamelets/error-handler/kamelet-binding-error-handler.yaml new file mode 100644 index 0000000..d731d1f --- /dev/null +++ b/examples/kamelets/error-handler/kamelet-binding-error-handler.yaml @@ -0,0 +1,38 @@ +# --------------------------------------------------------------------------- +# 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: http-error-source +spec: + source: + ref: + kind: Kamelet + apiVersion: camel.apache.org/v1alpha1 + name: timer-source + properties: + message: "Hello world!" + sink: + uri: https://log-source/failing-service + errorHandler: + ref: + kind: Kamelet + apiVersion: camel.apache.org/v1alpha1 + name: error-sink + properties: + defaultMessage: "ERROR ERROR!" diff --git a/examples/kamelets/error-handler/readme.md b/examples/kamelets/error-handler/readme.md new file mode 100644 index 0000000..5438050 --- /dev/null +++ b/examples/kamelets/error-handler/readme.md @@ -0,0 +1,49 @@ +# Kamelets Binding Error Handler example +This example shows how to create a simple _timer-source_ `kamelet` bound to a failing sink in a `KameletBinding`. With the support of the `ErrorHandler` we will be able to redirect all errors to a `Dead Letter Channel` _error-sink_ `Kamelet`. + +## Timer Source Kamelet +First of all, you must install the _timer-source_ Kamelet defined in `timer-source.kamelet.yaml` file: +``` +$ kubectl apply -f timer-source.kamelet.yaml +``` +You can check the newly created `kamelet` checking the list of kamelets available: +``` +$ kubectl get kamelets + +NAME PHASE +timer-source Ready +``` +## Error Sink Kamelet +Now it's the turn of installing the _error-sink_ Kamelet defined in `error-sink.kamelet.yaml` file: +``` +$ kubectl apply -f error-sink.kamelet.yaml +``` +You can check the newly created `kamelet` checking the list of kamelets available: +``` +$ kubectl get kamelets + +NAME PHASE +error-sink Ready +timer-source Ready +``` +## Error Handler Kamelet Binding +We can create a `KameletBinding` which is triggered by the _timer-source_ `Kamelet` and define a fake sink URI in order to make it fail on purpose. Then we can configure an _errorHandler_ as defined in `kamelet-binding-error-handler.yaml` file: +``` + errorHandler: + ref: + kind: Kamelet + apiVersion: camel.apache.org/v1alpha1 + name: log-sink + properties: + defaultMessage: "ERROR ERROR!" +``` +Execute the following command to start the `Integration`: +``` +kubectl apply -f kamelet-binding-error-handler.yaml +``` +As soon as the `Integration` starts, it will log a message error for every failure it will print: +``` +[1] 2021-03-16 15:11:33,099 INFO [error-sink] (Camel (camel-1) thread #0 - timer://tick) Exchange[ExchangePattern: InOnly, BodyType: String, Body: ERROR ERROR!] +[1] 2021-03-16 15:11:33,988 INFO [error-sink] (Camel (camel-1) thread #0 - timer://tick) Exchange[ExchangePattern: InOnly, BodyType: String, Body: ERROR ERROR!] +[1] 2021-03-16 15:11:34,988 INFO [error-sink] (Camel (camel-1) thread #0 - timer://tick) Exchange[ExchangePattern: InOnly, BodyType: String, Body: ERROR ERROR!] +``` \ No newline at end of file diff --git a/examples/kamelets/error-handler/timer-source.kamelet.yaml b/examples/kamelets/error-handler/timer-source.kamelet.yaml new file mode 100644 index 0000000..f837fb5 --- /dev/null +++ b/examples/kamelets/error-handler/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: "{{period}}" + steps: + - set-body: + constant: "{{message}}" + - to: "kamelet:sink"