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

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

commit 096e5de959593a4521300e0ffe669b6ec8fbd8a2
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Wed Apr 21 15:14:19 2021 +0200

    doc(example): error handler DLC
---
 .../error-handler/error-handler.kamelet.yaml       | 35 +++++++++++-----------
 .../kamelet-binding-error-handler.yaml             | 13 ++++----
 examples/kamelets/error-handler/readme.md          | 30 +++++++++++--------
 3 files changed, 43 insertions(+), 35 deletions(-)

diff --git a/examples/kamelets/error-handler/error-handler.kamelet.yaml 
b/examples/kamelets/error-handler/error-handler.kamelet.yaml
index dbfc4bb..9ace959 100644
--- a/examples/kamelets/error-handler/error-handler.kamelet.yaml
+++ b/examples/kamelets/error-handler/error-handler.kamelet.yaml
@@ -20,21 +20,22 @@ kind: Kamelet
 metadata:
   name: error-handler
 spec:
-  sources:
-  - content: |
-      import org.apache.camel.builder.RouteBuilder;
-      public class ErrorHandlerSource extends RouteBuilder {
-        @Override
-        public void configure() throws Exception {
-            
errorHandler(deadLetterChannel("log:error?showCaughtException=true&showException=true&showHeaders=true"));
-        }
-      }
-    name: ErrorHandlerSource.java
   definition:
-    title: "Error Handler Log DLC"
-    description: "Dead letter channel"
-# We can use the below once this is fixed 
https://issues.apache.org/jira/browse/CAMEL-16486
-#  flow:
-#    error-handler:
-#      dead-letter-channel:
-#        dead-letter-uri: 
log:error-sink?showCaughtException=true&showException=true&showHeaders=true
+    title: "Error Log Sink"
+    description: "Consume events from a channel"
+    required:
+      - message
+    properties:
+      message:
+        title: Message
+        description: The message to log
+        type: string
+        example: "error while checking the source"    
+  flow:
+    from:
+      uri: kamelet:source
+      steps:
+#      - to: my-dlc
+      - set-body:
+          constant: "{{message}}"
+      - 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
index 3602831..ae8eb78 100644
--- a/examples/kamelets/error-handler/kamelet-binding-error-handler.yaml
+++ b/examples/kamelets/error-handler/kamelet-binding-error-handler.yaml
@@ -31,9 +31,12 @@ spec:
       apiVersion: camel.apache.org/v1alpha1
       name: log-sink
   errorHandler:
-    ref:
-      kind: Kamelet
-      apiVersion: camel.apache.org/v1alpha1
-      name: error-handler    
-#    uri: kamelet:error-handler
+    type: dead-letter-channel
+    endpoint:
+      ref:
+        kind: Kamelet
+        apiVersion: camel.apache.org/v1alpha1
+        name: error-handler
+      properties:
+        message: "ERROR!"   
     
diff --git a/examples/kamelets/error-handler/readme.md 
b/examples/kamelets/error-handler/readme.md
index 5ff4777..dc4d75b 100644
--- a/examples/kamelets/error-handler/readme.md
+++ b/examples/kamelets/error-handler/readme.md
@@ -1,5 +1,5 @@
 # Kamelets Binding Error Handler example
-This example shows how to create a simple _source_ `kamelet` bound to 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`.
+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`.
 
 ## Incremental ID Source 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.
@@ -26,8 +26,8 @@ NAME                    PHASE
 log-sink                Ready
 incremental-id-source   Ready
 ```
-## Error handler  Kamelet
-We finally install an error handler as a dead letter channel as specified in 
`error-handler.kamelet.yaml` file. You can specify any kind of error handler as 
expected by Apache Camel runtime.
+## Error handler Kamelet
+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
 ```
@@ -41,14 +41,18 @@ log-sink                Ready
 incremental-id-source   Ready
 ```
 ## Error Handler Kamelet Binding
-We can create a `KameletBinding` which is triggered by the 
_incremental-id-source_ `Kamelet` and log events to _log-sink_ `Kamelet`. As 
this will sporadically fail, we can configure an _errorHandler_ as defined in 
`kamelet-binding-error-handler.yaml` file:
+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 can declare it as in 
`kamelet-binding-error-handler.yaml` file:
 ```
 ...
   errorHandler:
-    ref:
-      kind: Kamelet
-      apiVersion: camel.apache.org/v1alpha1
-      name: error-handler
+    type: dead-letter-channel
+    endpoint:
+      ref:
+        kind: Kamelet
+        apiVersion: camel.apache.org/v1alpha1
+        name: error-handler
+      properties:
+        message: "ERROR!"
 ```
 Execute the following command to start the `Integration`:
 ```
@@ -56,9 +60,9 @@ 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-13 10:33:38,375 INFO  [ok] (Camel (camel-1) thread #0 - 
timer://tick) Exchange[ExchangePattern: InOnly, BodyType: String, Body: 
Producing message #8]
-[1] 2021-04-13 10:33:39,376 INFO  [ok] (Camel (camel-1) thread #0 - 
timer://tick) Exchange[ExchangePattern: InOnly, BodyType: String, Body: 
Producing message #9]
-[1] 2021-04-13 10:33:40,409 INFO  [error] (Camel (camel-1) thread #0 - 
timer://tick) Exchange[ExchangePattern: InOnly, Headers: {firedTime=Tue Apr 13 
10:33:40 GMT 2021}, BodyType: String, Body: Producing message #10, 
CaughtExceptionType: org.apache.camel.CamelExecutionException, 
CaughtExceptionMessage: Exception occurred during execution on the exchange: 
Exchange[]]
-[1] 2021-04-13 10:33:41,375 INFO  [ok] (Camel (camel-1) thread #0 - 
timer://tick) Exchange[ExchangePattern: InOnly, BodyType: String, Body: 
Producing message #11]
+[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:03: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 with a `Dead Letter Channel` pointing to a persistent queue.
\ No newline at end of file
+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.
\ No newline at end of file

Reply via email to