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-jbang-examples.git


The following commit(s) were added to refs/heads/main by this push:
     new 3dc6150  connect/webhook-receiver - check the signature of payment 
webhooks, answer at once, record each event once (#149)
3dc6150 is described below

commit 3dc6150c806883fbac2e70b021a8654911a57da3
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Nov 30 07:00:17 2026 +0100

    connect/webhook-receiver - check the signature of payment webhooks, answer 
at once, record each event once (#149)
    
    Closes #148
    
    
    Claude-Session: https://claude.ai/code/session_016Y4dDi5iQNgtHrDdz2NpwF
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 .github/workflows/build.yml                        |   2 +
 README.md                                          |   1 +
 camel-jbang-example-catalog.json                   |  58 +++++++++++
 connect/README.md                                  |   1 +
 connect/webhook-receiver/README.md                 |  97 +++++++++++++++++++
 connect/webhook-receiver/application.properties    |  21 ++++
 connect/webhook-receiver/events/event-1.json       |   1 +
 connect/webhook-receiver/events/event-2.json       |   1 +
 .../webhook-receiver/events/event-3-resent.json    |   1 +
 .../webhook-receiver/events/event-4-forged.json    |   1 +
 connect/webhook-receiver/metadata.json             |  45 +++++++++
 connect/webhook-receiver/provider.camel.yaml       |  34 +++++++
 .../test/webhook-receiver.citrus.it.yaml           | 107 +++++++++++++++++++++
 .../webhook-receiver/webhook-receiver.camel.yaml   |  94 ++++++++++++++++++
 14 files changed, 464 insertions(+)

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 87c4163..61f0563 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -99,6 +99,8 @@ jobs:
             path: connect/stock-api
           - name: HTTP client
             path: connect/http-client
+          - name: Webhook receiver
+            path: connect/webhook-receiver
           - name: File processing
             path: connect/file-processing
           - name: MCP server
diff --git a/README.md b/README.md
index 3b06066..e79c77e 100644
--- a/README.md
+++ b/README.md
@@ -99,6 +99,7 @@ Files, an HTTP client and a REST server; everything runs 
inside the example.
 | [File processing](connect/file-processing/) | A courier route copies five 
files into an inbox; the invoices are checked, archived under a month directory 
and moved to done, the invoice with a negative amount is rejected with a 
warning and moved to failed, and the driver's note is left alone because only 
.json files are picked up. | nothing |
 | [Stock API](connect/stock-api/) | The shop's stock service on port 8080: GET 
/stock returns the stock file, GET /stock/{sku} returns one SKU as JSON and a 
404 with an error message for an unknown SKU. | nothing |
 | [HTTP client](connect/http-client/) | Every line of the three orders is 
checked against the stock service over HTTP, served by the same example; the 
log shows each line as ok, or back-order when the stock is short, with the 
stock level from the response. | nothing |
+| [Webhook receiver](connect/webhook-receiver/) | A simulated payment provider 
posts four signed payment webhooks; the shop checks each HMAC-SHA256 signature 
with Groovy and rejects the forged one with 401, answers 202 at once and 
records the payment two seconds later through a wire tap and a seda queue, and 
an idempotent consumer records the resent event only once. | nothing |
 
 ### [Connect to one service](connect-service/)
 
diff --git a/camel-jbang-example-catalog.json b/camel-jbang-example-catalog.json
index d25ba9f..1610eab 100644
--- a/camel-jbang-example-catalog.json
+++ b/camel-jbang-example-catalog.json
@@ -787,6 +787,64 @@
         ],
         "order": 2
     },
+    {
+        "name": "connect/webhook-receiver",
+        "title": "Webhook receiver",
+        "description": "A simulated payment provider posts four signed payment 
webhooks; the shop checks each HMAC-SHA256 signature with Groovy and rejects 
the forged one with 401, answers 202 at once and records the payment two 
seconds later through a wire tap and a seda queue, and an idempotent consumer 
records the resent event only once.",
+        "level": "connect",
+        "teaches": {
+            "components": [
+                "platform-http",
+                "http",
+                "seda",
+                "file",
+                "log"
+            ],
+            "eips": [
+                "choice",
+                "stop",
+                "wireTap",
+                "idempotentConsumer",
+                "delay",
+                "setVariable",
+                "setHeader",
+                "setBody",
+                "convertBodyTo",
+                "removeHeaders",
+                "unmarshal"
+            ],
+            "languages": [
+                "simple",
+                "groovy"
+            ],
+            "dataformats": [
+                "json"
+            ]
+        },
+        "tags": [
+            "shop",
+            "webhook",
+            "http",
+            "hmac",
+            "signature",
+            "async",
+            "idempotent"
+        ],
+        "bundled": true,
+        "requiresDocker": false,
+        "hasCitrusTests": true,
+        "files": [
+            "README.md",
+            "application.properties",
+            "events/event-1.json",
+            "events/event-2.json",
+            "events/event-3-resent.json",
+            "events/event-4-forged.json",
+            "provider.camel.yaml",
+            "webhook-receiver.camel.yaml"
+        ],
+        "order": 4
+    },
     {
         "name": "contracts/keycloak-security-rest",
         "title": "Keycloak security",
diff --git a/connect/README.md b/connect/README.md
index e6cfdff..88bea85 100644
--- a/connect/README.md
+++ b/connect/README.md
@@ -8,6 +8,7 @@ Files, an HTTP client and a REST server; everything runs inside 
the example.
 | [File processing](file-processing/) | A courier route copies five files into 
an inbox; the invoices are checked, archived under a month directory and moved 
to done, the invoice with a negative amount is rejected with a warning and 
moved to failed, and the driver's note is left alone because only .json files 
are picked up. | nothing |
 | [Stock API](stock-api/) | The shop's stock service on port 8080: GET /stock 
returns the stock file, GET /stock/{sku} returns one SKU as JSON and a 404 with 
an error message for an unknown SKU. | nothing |
 | [HTTP client](http-client/) | Every line of the three orders is checked 
against the stock service over HTTP, served by the same example; the log shows 
each line as ok, or back-order when the stock is short, with the stock level 
from the response. | nothing |
+| [Webhook receiver](webhook-receiver/) | A simulated payment provider posts 
four signed payment webhooks; the shop checks each HMAC-SHA256 signature with 
Groovy and rejects the forged one with 401, answers 202 at once and records the 
payment two seconds later through a wire tap and a seda queue, and an 
idempotent consumer records the resent event only once. | nothing |
 
 Start with [File processing](file-processing/); the examples read best in the 
order above, each one building on what the one before it set up.
 
diff --git a/connect/webhook-receiver/README.md 
b/connect/webhook-receiver/README.md
new file mode 100644
index 0000000..830558a
--- /dev/null
+++ b/connect/webhook-receiver/README.md
@@ -0,0 +1,97 @@
+# Webhook receiver
+
+The payment provider tells the shop about each payment with a webhook: an HTTP 
call with a JSON event, signed with a
+secret that both share. The shop checks the signature, answers at once, and 
records each payment once, afterwards.
+
+## What you will see
+
+```text
+INFO ... webhook-receiver.camel.yaml:48 : Event EVT-1: payment.succeeded for 
ORD-1001, accepted
+INFO ... provider.camel.yaml:33 : Provider: the shop answered 202 {"status": 
"accepted"}
+INFO ... webhook-receiver.camel.yaml:48 : Event EVT-2: payment.succeeded for 
ORD-1002, accepted
+INFO ... provider.camel.yaml:33 : Provider: the shop answered 202 {"status": 
"accepted"}
+INFO ... webhook-receiver.camel.yaml:93 : Payment of 49.40 EUR for ORD-1001 
recorded (event EVT-1)
+INFO ... webhook-receiver.camel.yaml:48 : Event EVT-1: payment.succeeded for 
ORD-1001, accepted
+INFO ... webhook-receiver.camel.yaml:84 : Event EVT-1 is a duplicate, skipped
+INFO ... provider.camel.yaml:33 : Provider: the shop answered 202 {"status": 
"accepted"}
+INFO ... webhook-receiver.camel.yaml:93 : Payment of 28.50 EUR for ORD-1002 
recorded (event EVT-2)
+INFO ... webhook-receiver.camel.yaml:33 : Rejected a webhook with a wrong 
signature
+INFO ... provider.camel.yaml:33 : Provider: the shop answered 401 {"error": 
"invalid signature"}
+```
+
+The provider gets its answer before the payment is recorded: recording takes 
two seconds, and the webhook does not
+wait for it.
+
+## Install Camel CLI
+
+Install [JBang](https://www.jbang.dev/download/) and the Camel CLI as 
described in the
+[root README](../../README.md#install-the-camel-cli); `camel --version` 
confirms the install.
+
+## Run it
+
+```shell
+camel run *
+```
+
+This runs the shop's webhook and a simulated payment provider in one app, on 
port 8080. Stop the example with
+`ctrl` + `c`.
+
+## How it works
+
+- `events/` holds four payment events. `event-3-resent.json` is EVT-1 again: a 
provider sends an event again when it is
+  not sure that it arrived. `event-4-forged.json` claims that the pending 
order ORD-1003 is paid, and is signed with
+  another key, as a forger would.
+- `provider.camel.yaml` plays the payment provider, so the example needs no 
other service. It posts each event to the
+  webhook with the header `X-Signature`: the hex HMAC-SHA256 of the body, 
computed with Groovy and the shared secret.
+  `throwExceptionOnFailure: false` lets it log the shop's answer, also a 401.
+- `webhook-receiver.camel.yaml` receives `POST /webhooks/payments` with 
`platform-http`. It keeps the body as text
+  (`convertBodyTo`), because the signature is computed over the body exactly 
as it arrived, and computes the expected
+  signature with Groovy. A wrong or missing signature gets a 401, and `stop` 
ends the route.
+- A valid event is logged, sent on with `wireTap` to the `seda` queue 
`payments`, and answered with 202 at once. The
+  `payments` route records the payment, which takes two seconds (`delay`).
+- An `idempotentConsumer` with an in-memory repository records each event id 
once and logs the resent event as a
+  duplicate.
+- `application.properties` holds the shared secret and the address the 
provider posts to.
+
+## Build it step by step
+
+Ask your assistant, or type it yourself, one step at a time, and run after 
each:
+
+1. A route on `platform-http` for `POST /webhooks/payments` that logs the 
event type and id, and a provider route that
+   posts the files in `events/` to it.
+2. Check the header `X-Signature`: it is the HMAC-SHA256 of the body with the 
secret `{{webhook.secret}}`, in hex.
+   Reject a wrong or missing signature with HTTP 401.
+3. Answer at once with 202, and record the payment afterwards. Recording takes 
two seconds.
+4. The provider sometimes sends the same event twice. Record each event id 
only once.
+
+## Try changing
+
+- Remove the `wireTap` and call the `payments` route directly: the provider 
now waits two seconds for each answer. A
+  real provider gives up after a few seconds and sends the event again.
+- Change `webhook.secret` in `application.properties` only: the provider still 
signs with the old secret in the same
+  app, so both sides change together. Run `provider.camel.yaml` as its own app 
with another secret, and every webhook
+  gets a 401.
+- Keep the secret out of `application.properties`: pass it as an environment 
variable (`WEBHOOK_SECRET`), or read it
+  from a secret store, as 
[kubernetes-secrets](../../cloud/kubernetes-secrets/) does.
+
+## Integration testing
+
+The example comes with a test in the [Citrus](https://citrusframework.org/) 
YAML DSL,
+`test/webhook-receiver.citrus.it.yaml`, which the Camel CLI runs:
+
+```shell
+camel test run test/webhook-receiver.citrus.it.yaml
+```
+
+The test runs the webhook alone and plays the provider itself: it posts signed 
events and a forged one, and verifies
+the 202 and 401 answers, the recorded payments and the duplicate.
+
+## Help and contributions
+
+If you hit any problem using Camel or have some feedback, then please
+[let us know](https://camel.apache.org/community/support/).
+
+We also love contributors, so
+[get involved](https://camel.apache.org/community/contributing/) :-)
+
+The Camel riders!
diff --git a/connect/webhook-receiver/application.properties 
b/connect/webhook-receiver/application.properties
new file mode 100644
index 0000000..1249d31
--- /dev/null
+++ b/connect/webhook-receiver/application.properties
@@ -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.
+
+# the secret the payment provider and the shop share; the provider signs each 
webhook with it
+webhook.secret=shop-webhook-secret
+# where the provider in provider.camel.yaml posts its webhooks
+webhook.url=http://localhost:8080/webhooks/payments
diff --git a/connect/webhook-receiver/events/event-1.json 
b/connect/webhook-receiver/events/event-1.json
new file mode 100644
index 0000000..7f5662e
--- /dev/null
+++ b/connect/webhook-receiver/events/event-1.json
@@ -0,0 +1 @@
+{"eventId": "EVT-1", "type": "payment.succeeded", "orderId": "ORD-1001", 
"amount": "49.40", "currency": "EUR"}
diff --git a/connect/webhook-receiver/events/event-2.json 
b/connect/webhook-receiver/events/event-2.json
new file mode 100644
index 0000000..c3fc777
--- /dev/null
+++ b/connect/webhook-receiver/events/event-2.json
@@ -0,0 +1 @@
+{"eventId": "EVT-2", "type": "payment.succeeded", "orderId": "ORD-1002", 
"amount": "28.50", "currency": "EUR"}
diff --git a/connect/webhook-receiver/events/event-3-resent.json 
b/connect/webhook-receiver/events/event-3-resent.json
new file mode 100644
index 0000000..7f5662e
--- /dev/null
+++ b/connect/webhook-receiver/events/event-3-resent.json
@@ -0,0 +1 @@
+{"eventId": "EVT-1", "type": "payment.succeeded", "orderId": "ORD-1001", 
"amount": "49.40", "currency": "EUR"}
diff --git a/connect/webhook-receiver/events/event-4-forged.json 
b/connect/webhook-receiver/events/event-4-forged.json
new file mode 100644
index 0000000..d9ecff3
--- /dev/null
+++ b/connect/webhook-receiver/events/event-4-forged.json
@@ -0,0 +1 @@
+{"eventId": "EVT-4", "type": "payment.succeeded", "orderId": "ORD-1003", 
"amount": "52.95", "currency": "EUR"}
diff --git a/connect/webhook-receiver/metadata.json 
b/connect/webhook-receiver/metadata.json
new file mode 100644
index 0000000..337d6ca
--- /dev/null
+++ b/connect/webhook-receiver/metadata.json
@@ -0,0 +1,45 @@
+{
+    "title": "Webhook receiver",
+    "description": "A simulated payment provider posts four signed payment 
webhooks; the shop checks each HMAC-SHA256 signature with Groovy and rejects 
the forged one with 401, answers 202 at once and records the payment two 
seconds later through a wire tap and a seda queue, and an idempotent consumer 
records the resent event only once.",
+    "level": "connect",
+    "order": 4,
+    "teaches": {
+        "components": [
+            "platform-http",
+            "http",
+            "seda",
+            "file",
+            "log"
+        ],
+        "eips": [
+            "choice",
+            "stop",
+            "wireTap",
+            "idempotentConsumer",
+            "delay",
+            "setVariable",
+            "setHeader",
+            "setBody",
+            "convertBodyTo",
+            "removeHeaders",
+            "unmarshal"
+        ],
+        "languages": [
+            "simple",
+            "groovy"
+        ],
+        "dataformats": [
+            "json"
+        ]
+    },
+    "tags": [
+        "shop",
+        "webhook",
+        "http",
+        "hmac",
+        "signature",
+        "async",
+        "idempotent"
+    ],
+    "bundled": true
+}
diff --git a/connect/webhook-receiver/provider.camel.yaml 
b/connect/webhook-receiver/provider.camel.yaml
new file mode 100644
index 0000000..ac71a72
--- /dev/null
+++ b/connect/webhook-receiver/provider.camel.yaml
@@ -0,0 +1,34 @@
+# Plays the payment provider, so the example needs no other service: it posts 
each event in events/ to the shop's
+# webhook, signed with the shared secret. event-4-forged.json is signed with 
another key, as a forger would.
+- route:
+    id: provider
+    from:
+      uri: file
+      parameters:
+        directoryName: events
+        noop: true
+        sortBy: "file:name"
+        maxMessagesPerPoll: 1
+        eagerMaxMessagesPerPoll: false
+        delay: 1000
+      steps:
+        - convertBodyTo:
+            type: String
+        - setHeader:
+            name: X-Signature
+            expression:
+              groovy:
+                expression: >-
+                  def key = headers.CamelFileName.contains('forged') ? 
'not-the-secret' : '{{webhook.secret}}';
+                  def mac = javax.crypto.Mac.getInstance('HmacSHA256');
+                  mac.init(new 
javax.crypto.spec.SecretKeySpec(key.getBytes('UTF-8'), 'HmacSHA256'));
+                  mac.doFinal(body.getBytes('UTF-8')).encodeHex().toString()
+        - removeHeaders:
+            pattern: "CamelFile*"
+        - to:
+            uri: "{{webhook.url}}"
+            parameters:
+              httpMethod: POST
+              throwExceptionOnFailure: false
+        - log:
+            message: "Provider: the shop answered 
${header.CamelHttpResponseCode} ${body}"
diff --git a/connect/webhook-receiver/test/webhook-receiver.citrus.it.yaml 
b/connect/webhook-receiver/test/webhook-receiver.citrus.it.yaml
new file mode 100644
index 0000000..0b83620
--- /dev/null
+++ b/connect/webhook-receiver/test/webhook-receiver.citrus.it.yaml
@@ -0,0 +1,107 @@
+name: webhook-receiver-test
+description: The webhook checks signatures, answers at once and records each 
payment once, as its README shows
+actions:
+  - camel:
+      cli:
+        run:
+          integration:
+            name: "webhook-receiver"
+            file: "../webhook-receiver.camel.yaml"
+            systemProperties:
+              file: "../application.properties"
+  - camel:
+      cli:
+        verify:
+          integration: "webhook-receiver"
+          logMessage: "(webhook-receiver) started"
+  # a payment event signed with the shared secret (the hex HMAC-SHA256 of the 
body)
+  - http:
+      client: "http://localhost:8080";
+      sendRequest:
+        POST:
+          path: "/webhooks/payments"
+          contentType: "application/json"
+          headers:
+            - name: "X-Signature"
+              value: 
"0c6f39a1f201956247b1456447c474a6af24b7b126a9d96fc854446aa8d31515"
+          body:
+            data: '{"eventId": "EVT-1", "type": "payment.succeeded", 
"orderId": "ORD-1001", "amount": "49.40", "currency": "EUR"}'
+  - http:
+      client: "http://localhost:8080";
+      receiveResponse:
+        response:
+          status: "202"
+  - http:
+      client: "http://localhost:8080";
+      sendRequest:
+        POST:
+          path: "/webhooks/payments"
+          contentType: "application/json"
+          headers:
+            - name: "X-Signature"
+              value: 
"9d8903b2ef8e2c0447ce804697666ed4594e12535109a06d4f077aaa459b0340"
+          body:
+            data: '{"eventId": "EVT-2", "type": "payment.succeeded", 
"orderId": "ORD-1002", "amount": "28.50", "currency": "EUR"}'
+  - http:
+      client: "http://localhost:8080";
+      receiveResponse:
+        response:
+          status: "202"
+  # the first event again: accepted, but recorded only once
+  - http:
+      client: "http://localhost:8080";
+      sendRequest:
+        POST:
+          path: "/webhooks/payments"
+          contentType: "application/json"
+          headers:
+            - name: "X-Signature"
+              value: 
"0c6f39a1f201956247b1456447c474a6af24b7b126a9d96fc854446aa8d31515"
+          body:
+            data: '{"eventId": "EVT-1", "type": "payment.succeeded", 
"orderId": "ORD-1001", "amount": "49.40", "currency": "EUR"}'
+  - http:
+      client: "http://localhost:8080";
+      receiveResponse:
+        response:
+          status: "202"
+  # a forged event: the signature is not made with the shared secret
+  - http:
+      client: "http://localhost:8080";
+      sendRequest:
+        POST:
+          path: "/webhooks/payments"
+          contentType: "application/json"
+          headers:
+            - name: "X-Signature"
+              value: 
"0c6f39a1f201956247b1456447c474a6af24b7b126a9d96fc854446aa8d31515"
+          body:
+            data: '{"eventId": "EVT-4", "type": "payment.succeeded", 
"orderId": "ORD-1003", "amount": "52.95", "currency": "EUR"}'
+  - http:
+      client: "http://localhost:8080";
+      receiveResponse:
+        response:
+          status: "401"
+        validate:
+          - jsonPath:
+              - expression: "$.error"
+                value: "invalid signature"
+  - camel:
+      cli:
+        verify:
+          integration: "webhook-receiver"
+          logMessage: "Payment of 49.40 EUR for ORD-1001 recorded (event 
EVT-1)"
+  - camel:
+      cli:
+        verify:
+          integration: "webhook-receiver"
+          logMessage: "Payment of 28.50 EUR for ORD-1002 recorded (event 
EVT-2)"
+  - camel:
+      cli:
+        verify:
+          integration: "webhook-receiver"
+          logMessage: "Event EVT-1 is a duplicate, skipped"
+  - camel:
+      cli:
+        verify:
+          integration: "webhook-receiver"
+          logMessage: "Rejected a webhook with a wrong signature"
diff --git a/connect/webhook-receiver/webhook-receiver.camel.yaml 
b/connect/webhook-receiver/webhook-receiver.camel.yaml
new file mode 100644
index 0000000..e591797
--- /dev/null
+++ b/connect/webhook-receiver/webhook-receiver.camel.yaml
@@ -0,0 +1,94 @@
+# The payment provider tells the shop about payments with webhooks: a JSON 
event, signed with a secret that both
+# share. The shop checks the signature, answers at once, and records the 
payment afterwards, once per event.
+- beans:
+    - name: eventIds
+      type: 
org.apache.camel.support.processor.idempotent.MemoryIdempotentRepository
+
+- route:
+    id: webhook
+    from:
+      uri: platform-http
+      parameters:
+        path: /webhooks/payments
+        httpMethodRestrict: POST
+      steps:
+        # the signature is computed over the body exactly as it arrived, so 
keep it as text
+        - convertBodyTo:
+            type: String
+        # X-Signature is the hex HMAC-SHA256 of the body with the shared secret
+        - setVariable:
+            name: signature
+            expression:
+              groovy:
+                expression: >-
+                  def mac = javax.crypto.Mac.getInstance('HmacSHA256');
+                  mac.init(new 
javax.crypto.spec.SecretKeySpec('{{webhook.secret}}'.getBytes('UTF-8'), 
'HmacSHA256'));
+                  mac.doFinal(body.getBytes('UTF-8')).encodeHex().toString()
+        - choice:
+            when:
+              - expression:
+                  simple:
+                    expression: "${header.X-Signature} != 
${variable.signature}"
+                steps:
+                  - log:
+                      message: "Rejected a webhook with a wrong signature"
+                  - setHeader:
+                      name: CamelHttpResponseCode
+                      expression:
+                        constant:
+                          expression: "401"
+                  - setBody:
+                      expression:
+                        constant:
+                          expression: '{"error": "invalid signature"}'
+                  - stop: {}
+        - unmarshal:
+            json:
+              library: Jackson
+        - log:
+            message: "Event ${body[eventId]}: ${body[type]} for 
${body[orderId]}, accepted"
+        # the provider waits for the answer, so answer at once and record the 
payment afterwards
+        - wireTap:
+            uri: seda:payments
+        - setHeader:
+            name: CamelHttpResponseCode
+            expression:
+              constant:
+                expression: "202"
+        - setBody:
+            expression:
+              constant:
+                expression: '{"status": "accepted"}'
+
+# Records each payment once: the provider sends an event again when it is not 
sure it arrived
+- route:
+    id: payments
+    from:
+      uri: seda
+      parameters:
+        name: payments
+      steps:
+        - idempotentConsumer:
+            expression:
+              simple:
+                expression: "${body[eventId]}"
+            idempotentRepository: eventIds
+            skipDuplicate: false
+            steps:
+              - choice:
+                  when:
+                    - expression:
+                        simple:
+                          expression: 
"${exchangeProperty.CamelDuplicateMessage} == true"
+                      steps:
+                        - log:
+                            message: "Event ${body[eventId]} is a duplicate, 
skipped"
+                  otherwise:
+                    steps:
+                      # recording a payment is slow, which is why the webhook 
does not wait for it
+                      - delay:
+                          expression:
+                            constant:
+                              expression: "2000"
+                      - log:
+                          message: "Payment of ${body[amount]} 
${body[currency]} for ${body[orderId]} recorded (event ${body[eventId]})"

Reply via email to