allthingssecurity opened a new pull request, #30533: URL: https://github.com/apache/camel/pull/30533
# Description [CAMEL-27286](https://issues.apache.org/jira/browse/CAMEL-27286) The `consul:kv` consumer sets the `CamelConsulKey` header to the key that changed, and the `consul:event` consumer sets it to the event name. All `consul:kv` actions and the `consul:event` actions take the key from that header before the `key` option of the endpoint, so a route from a consumer to a producer with another key acted on the key the message came from: - `from("consul:kv?key=config/a").to("consul:kv?key=config/b&action=PUT")` wrote the value back to `config/a`. A PUT changes the modify index even with the same value, so the watch fired again and the route looped for ever, and `config/b` was never written. - With `action=DELETE_KEY` (or `DELETE_KEYS`, `LOCK`, `UNLOCK`) it deleted or locked the watched key instead of the key of the endpoint. - `from("consul:event?key=a").to("consul:event?key=b&action=FIRE")` fired event `a` again (an endless loop of events) and never `b`. This is the class of CAMEL-25898 (#28426, camel-ibm-cos) and CAMEL-25227 (#27213, camel-azure-eventhubs); camel-infinispan made the `key` option of its producer win over the key header for the same reason (4.24 upgrade guide). Fix: - The key/value and event consumers also set the exchange property `CamelConsulReceivedKey` (`ConsulConstants.CONSUL_RECEIVED_KEY`) to the key they received. - `AbstractConsulProducer.getKey` / `getMandatoryKey` replace the header lookups of `ConsulKeyValueProducer` and `ConsulEventProducer`: when the endpoint has a `key` and the `CamelConsulKey` header still holds the received key, the key of the endpoint is used. A key header set by the route is still used, and a producer without a `key` still acts on the received key, so the common forms keep working: `setHeader(CamelConsulKey, ...)` before a producer, and a recursive watch that deletes or reads each changed key with `consul:kv?action=DELETE_KEY` (tested). - Same approach as the received partition properties of camel-azure-eventhubs, rather than an override header (as ibm-cos did), so that routes that set `CamelConsulKey` keep working unchanged. The header description (generated JSON, DSL) is unchanged. A route that wants to act on the received key with a producer that has a `key` of its own removes the property; the component page says so and the 4.24 upgrade guide has an entry. Tests: `ConsulProducerReceivedKeyTest` runs the real consumers and producers against mocked `KeyValueClient` / `EventClient` (as `ConsulKeyValueWatchTest` and `ConsulEventWatchTest` do; the blocking queries stay pending until the test answers them): PUT, DELETE_KEY and FIRE from a consumer of one key to a producer with another key must act on the key of the producer and never on the received key; controls: a recursive watch to `consul:kv?action=DELETE_KEY` without key deletes the received key, and a key header set by the route is used. Runs (offline; consul-client 1.12.1, the version cached on my machine, main uses 1.12.2; none of the client calls used here changed): the three bridge tests fail on main (`putValue`/`deleteKey`/`fireEvent` called with the received key), the two controls pass on main and with the fix; camel-consul module tests (unit tests, the ITs need a Consul container) 34 run, 0 failures; the new test class 20 times in one JVM: 100 of 100. # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it): [CAMEL-27286](https://issues.apache.org/jira/browse/CAMEL-27286). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. (I built the core modules and camel-consul with the formatter and import-sort plugins, and copied the component page to the catalog. No option or header metadata changed. I did not run the full root build.) # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer. _Claude Code on behalf of allthingssecurity_ 🤖 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]
