davsclaus opened a new pull request, #30456: URL: https://github.com/apache/camel/pull/30456
[CAMEL-27261](https://issues.apache.org/jira/browse/CAMEL-27261) ### The bug A Kamelet EIP (`kamelet` with nested steps) got its endpoint with `camelContext.getEndpoint("kamelet://" + name)`, the endpoint the URI shares. It registers its nested steps under that endpoint's key (`templateId/routeId`) with `KameletComponent.addKameletEip`, and the `kamelet:sink` of the Kamelet route looks that key up to continue. So uses with the same name and options shared one endpoint, one Kamelet route and one callback key: - **Two Kamelet EIPs with the same name and options, in different routes:** the last one registered wins. The first route's messages run the second route's nested steps, and the first route's own steps never run. Nothing fails; the messages just go the wrong way. - **A `to("kamelet:X?opts")` and a Kamelet EIP with the same name and options:** the `to` route's messages also run the EIP's nested steps, on their own thread. This affects every action Kamelet, because Camel adds `kamelet:sink` to the end of an action template. Reproduced with `camel run` on 4.10.0, 4.23.0 and 4.24.0-SNAPSHOT, with the catalog's `insert-header-action`. Two routes each using it as an EIP with `name=foo&value=bar` log `B2 nested step got: from-B1`. ### The fix `KameletProcessor` now uses a **prototype endpoint** of its own (`getPrototypeEndpoint`, as `toD` with `cacheSize=-1` does). Each Kamelet EIP therefore has its own Kamelet route, with a generated route id, and its own callback key. A `to("kamelet:...")` keeps the shared endpoint and never shares a route with an EIP. The EIP shuts its endpoint down with itself, and the endpoint removes its Kamelet route (the existing `KameletEndpoint.doShutdown` logic). So removing a route with a Kamelet EIP while the context runs doesn't leave its Kamelet route behind. A route id given in the name (`my-kamelet/myRoute`) is still shared on purpose, as before. I considered putting the callback on the exchange instead. That would break silently when an aggregation strategy inside the Kamelet creates a new exchange, so I dropped it. ### Behaviour change An application with several Kamelet EIPs with the same name and options now has one Kamelet route per EIP (`my-action-1`, `my-action-2`, …), where it had one. There's a note in the 4.24 upgrade guide. ### Tests New `KameletEipSameOptionsTest`: - two Kamelet EIPs with the same options each continue with their own nested steps; - a `to("kamelet:...")` with the same options doesn't run an EIP's steps, and gets the result of the action; - after adding a route with a Kamelet EIP at runtime, then removing it, the route count is back where it was (with Awaitility, as the component removes routes asynchronously). The first two fail without the fix (`mock://b1-nested ... Expected: <1> but was: <0>`, `mock://b2-nested ... Expected: <0> but was: <1>`). - camel-kamelet: all 172 tests pass (2 skipped). - camel-yaml-dsl: the Kamelet tests (`Kamelet*Test`, `SplitKameletTest`, `CallNestedKameletTest`), 32, pass, run in one reactor build with this camel-kamelet. _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]
