This example shows how to create a simple source Kamelet
which sends periodically events (and certain failures). The events are consumed by a log sink in a KameletBinding
. With the support of the ErrorHandler
we will be able to redirect all errors to a Dead Letter Channel
error-handler Kamelet
.
First of all, you must install the incremental-id-source Kamelet defined in incremental-id-source.kamelet.yaml
file. This source will emit events every second with an autoincrement counter that will be forced to fail when the number 0 is caught. With this trick, we will simulate possible event faults.
$ kubectl apply -f incremental-id-source.kamelet.yaml
You can check the newly created kamelet
checking the list of kamelets available:
$ kubectl get kamelets NAME PHASE incremental-id-source Ready
Now it's the turn of installing the log-sink_ Kamelet defined in log-sink.kamelet.yaml
file:
$ kubectl apply -f log-sink.kamelet.yaml
You can check the newly created kamelet
checking the list of kamelets available:
$ kubectl get kamelets NAME PHASE log-sink Ready incremental-id-source Ready
We finally install an error handler as specified in error-handler.kamelet.yaml
file. This is a simple logger, but you can use any endpoint to collect and store the failing events.
$ kubectl apply -f error-handler.kamelet.yaml
You can check the newly created kamelet
checking the list of kamelets available:
$ kubectl get kamelets NAME PHASE error-handler Ready log-sink Ready incremental-id-source Ready
We can create a KameletBinding
which is started by the incremental-id-source Kamelet
and log events to log-sink Kamelet
. As this will sporadically fail, we can configure an errorHandler with the error-handler Kamelet
as Dead Letter Channel. We want to configure also some redelivery policies. We can declare it as in kamelet-binding-error-handler.yaml
file:
... errorHandler: dead-letter-channel: endpoint: ref: kind: Kamelet apiVersion: camel.apache.org/v1alpha1 name: error-handler properties: message: "ERROR!" parameters: maximumRedeliveries: 3 redeliveryDelay: 2000
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 the events on the ok
log channel and errors on the error
log channel:
[1] 2021-04-21 13:03:43,773 INFO [sink] (Camel (camel-1) thread #0 - timer://tick) Exchange[ExchangePattern: InOnly, BodyType: String, Body: Producing message #8] [1] 2021-04-21 13:03:44,774 INFO [sink] (Camel (camel-1) thread #0 - timer://tick) Exchange[ExchangePattern: InOnly, BodyType: String, Body: Producing message #9] [1] 2021-04-21 13:03:45,898 INFO [error-sink] (Camel (camel-1) thread #0 - timer://tick) Exchange[ExchangePattern: InOnly, BodyType: String, Body: ERROR!] [1] 2021-04-21 13:09:46,775 INFO [sink] (Camel (camel-1) thread #0 - timer://tick) Exchange[ExchangePattern: InOnly, BodyType: String, Body: Producing message #11]
This example is useful to guide you through the configuration of an error handler. In a production environment you will likely configure the error handler Kamelet
pointing to a persistent queue.