davsclaus opened a new pull request, #30578: URL: https://github.com/apache/camel/pull/30578
Stacked on #30577 (CAMEL-27360: eventbridge queue policy). Retarget to `main` once #30577 is merged. JIRA: [CAMEL-27378](https://issues.apache.org/jira/browse/CAMEL-27378) ## What was wrong With `autoCreateQueue` and `deleteQueueOnShutdown=false`, the consumer created a queue named `camel-eventbridge-<rule>-<random>`, and removed the queue's target from the rule on shutdown. The next start created another queue, so every restart left a queue behind, which no longer had a target. This also did not match the option description ("delete the auto-created SQS queue **and remove the EventBridge target** on shutdown"). ## The fix: reuse the queue I went with a stable, deterministic name rather than documenting that `deleteQueueOnShutdown=false` only works with `queueUrl`: - A queue that is kept on shutdown is named `camel-eventbridge-<rule name>-<16 hex of sha256(eventBus + "/" + rule)>`. SQS `CreateQueue` with the name of an existing queue (and no attributes) returns that queue, so the next start reuses it. The hash tells apart rules with the same name on other event buses, and rule names that get cut. - The queue is then treated like a queue given with `queueUrl`: its target id is derived from the queue ARN (`targetIdForQueue`, from CAMEL-25759), and the target stays on the rule on shutdown. The queue collects the events while the consumer is stopped, and several consumers that share the queue update one target instead of adding duplicates. If one consumer removed a shared target on stop, the others would stop getting events. - With the default `deleteQueueOnShutdown=true` nothing changes: every consumer gets its own queue with a random part (each one gets a copy of the events), and the queue and its target are removed on shutdown. **With the queue policy from #30577:** the policy only allows the rule's ARN (`aws:SourceArn`). The rule ARN is deterministic for a rule name and bus, and the consumer sets the policy again on every start (`SetQueueAttributes`), so a reused queue still accepts only its own rule. The predictable name gives no extra access, because queue access is controlled by IAM in the same account. The `camel-eventbridge-` prefix plus the hash makes a clash with a queue someone else made unlikely. The rule name part of the queue name now has dots replaced with `-` and is cut to 45 characters. A rule name can have up to 64 characters including dots, but a queue name has at most 80 characters of `[-_A-Za-z0-9]`, so such rule names used to give an invalid queue name. Docs: the option description, the "How It Works" section and the options table are updated (plus the catalog copy and the regenerated endpoint/component DSL). There is a new upgrade guide entry because the target is now kept and the queue name changes for `deleteQueueOnShutdown=false`. ## Tests - `EventbridgeConsumerTest`: new tests cover the kept queue and target, reuse on restart (same queue name and same target id on both starts), a new queue per start with `deleteQueueOnShutdown=true`, and the queue name (stable, differs per event bus, at most 80 valid characters for a 64-character rule with dots). `testDeleteQueueOnShutdownFalseKeepsQueue` asserted that the target was removed. It is now `...KeepsQueueAndTarget`. - New `EventbridgeConsumerKeepQueueIT` (Floci test-infra): starts the route, stops it, sends an event while it is stopped, and starts it again. It checks that the event is received, that there is still one queue for the rule, and that the rule has one target. It **fails without the fix** and passes with it. - `mvn -o test` in camel-aws2-eventbridge: 41 tests, 0 failures. - `mvn -o verify -Dit.test=EventbridgeConsumerKeepQueueIT,EventbridgeConsumerQueuePolicyIT,EventbridgeConsumerIT`: 2 passed. The 5 tests of `EventbridgeConsumerIT` are skipped, because the class is `@Disabled` on main. _Claude Code on behalf of davsclaus_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
