davsclaus opened a new pull request, #3325: URL: https://github.com/apache/camel-kamelets/pull/3325
Fixes #1931. S3, Azure Storage, Cloud Storage and Ceph deliver their events **at least once**, so the same event can reach an event-based source twice. The message ID of the queue does not identify it: a copy that S3 or Cloud Storage sends again comes in a new SQS or Pub/Sub message. With `getObject` (or `getBlob`) the body becomes the file, and the fields that identify the event are gone, so a route could not skip copies after the Kamelet. Each of the four event-based sources now gives a header that is the same in every copy of an event. To process each event once, the route puts its steps in an `idempotentConsumer` step on that header, with the repository it chooses: in memory for one process, or shared (`camel-infinispan`, `camel-sql`, ...) with more than one replica. The Kamelets do not skip copies themselves, because an in-memory list would only work within one replica and until a restart. | Kamelet | Header | Value | |---|---|---| | `aws-s3-event-based-source` | `aws-s3-event-id` (new) | `<detail-type>/<bucket>/<key>/<sequencer>`, or the EventBridge `id` for an event without a sequencer | | `azure-storage-blob-event-based-source` | `azure-storage-blob-event-id` (new) | `<eventType>/<subject>/<data.sequencer>`, or the event `id` for an event without a sequencer | | `google-storage-event-based-source` | `google-storage-event-id` (new) | `<eventType>/<bucketId>/<objectId>/<objectGeneration>/<metageneration>`; for a notification without payload (`payloadFormat` `NONE`), `eventTime` takes the place of the metageneration | | `ceph-event-based-source` | `ceph-event-id` (unchanged) | the `eventId` of the Ceph notification, already set; only the description is new | The headers are set in both modes, before `getObject` or `getBlob` replaces the body. The `Output:` and `Good to know:` paragraphs say what the header is and how to skip the copies. Why these values: - **S3:** the EventBridge `id` is "a UUID generated for every event", and AWS does not say a copy keeps it. The `sequencer` orders the events of one key, and only PUT and DELETE events have it ([S3 docs](https://docs.aws.amazon.com/AmazonS3/latest/userguide/notification-content-structure.html)). - **Azure:** storage events are at-least-once "due to retries between backend nodes and services"; the `sequencer` orders the events of one blob ([Azure docs](https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-event-overview)). - **Cloud Storage:** "you could receive multiple messages, with multiple IDs, that represent the same Cloud Storage event" ([GCS docs](https://docs.cloud.google.com/storage/docs/pubsub-notifications)). The generation changes with each version of a file, and the metageneration with each change of its metadata, so together they identify the change. Only the JSON payload has the metageneration, so the Kamelet checks `payloadFormat` before it reads the body. It now declares `camel:jsonpath`. ### Tests - New `aws/s3/aws-s3-event-based-source-duplicates`: an `idempotentConsumer` step after the Kamelet, with a `MemoryIdempotentRepository`. A copy of an event with another EventBridge `id`, and a copy of an event without a sequencer, are both skipped. The next events come through with the expected IDs. - `aws-s3-event-based-source-get-object` and `aws-s3-ceph-event-based-source-get-object`: the file comes with the event ID header. - `azure-storage-blob-event-based-source-route` (event with a sequencer) and `google-storage-event-based-source-route` (a real notification of the Floci GCP emulator): the header has the expected value. Local runs against the current 4.24.0-SNAPSHOT: - `AwsIT#awsS3`: 8/8 passed - `AzureIT#azure`: 17/17 passed - `GoogleCloudIT#google`: 7/7 passed - `./mvnw clean install -DskipITs`: passes Not covered by a test: the `eventTime` fallback of `google-storage-event-based-source`. The Floci GCP emulator sends no `eventTime` attribute and no notification for a change of metadata, but real Cloud Storage puts `eventTime` on every notification. _Claude Code on behalf of Claus Ibsen_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
