This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch CAMEL-27262 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 7b504574a1d383d1ee7203d478db8c65fa3dbe61 Author: Claus Ibsen <[email protected]> AuthorDate: Thu Nov 19 22:29:16 2026 +0100 CAMEL-27262: camel-kamelet - each Kamelet EIP gets its own Kamelet route, so EIPs with the same name and options run their own nested steps A Kamelet EIP got its endpoint from the context by the uri kamelet://<name>, and the context caches endpoints by uri. Two EIPs with the same name and options shared one endpoint, so one Kamelet route and one key for the nested steps that kamelet:sink continues with: the last EIP registered won, and the messages of the first ran the nested steps of the second. A to with the same uri ran the nested steps of the EIP as well. The EIP now adds the reserved uuid parameter, which the component drops, with the ids of its route and processor to the uri, so the endpoint, the Kamelet route and the key are its own. A to with the plain uri is no longer affected. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../camel/component/kamelet/KameletProcessor.java | 18 ++++- .../component/kamelet/KameletEipSameNameTest.java | 80 ++++++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) diff --git a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletProcessor.java b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletProcessor.java index 4d41da39bb0b..1a723205d076 100644 --- a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletProcessor.java +++ b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletProcessor.java @@ -134,7 +134,7 @@ public class KameletProcessor extends BaseProcessorSupport // use the scoped API for ScopedValue compatibility on JDK 25+ Runnable initProducer = () -> { try { - this.producer = (KameletProducer) camelContext.getEndpoint("kamelet://" + name).createAsyncProducer(); + this.producer = (KameletProducer) camelContext.getEndpoint(endpointUri()).createAsyncProducer(); } catch (Exception e) { throw new RuntimeException(e); } @@ -161,6 +161,22 @@ public class KameletProcessor extends BaseProcessorSupport component.addKameletEip(producer.getKey(), processor); } + /** + * The uri of the Kamelet endpoint of this EIP. The context caches endpoints by uri, and the Kamelet route and the + * key the nested steps are registered under come from the endpoint: the reserved uuid parameter, which the + * component drops, makes the uri unique to this EIP, so EIPs with the same name and options, and a to with that + * uri, do not share the route and run the nested steps of another EIP. + */ + private String endpointUri() { + String unique; + if (parentRouteId != null && parentProcessorId != null) { + unique = parentRouteId + "-" + parentProcessorId; + } else { + unique = Kamelet.extractUuid(); + } + return "kamelet://" + name + (name.contains("?") ? "&" : "?") + Kamelet.PARAM_UUID + "=" + unique; + } + @Override protected void doStart() throws Exception { ServiceHelper.startService(processor, producer); diff --git a/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletEipSameNameTest.java b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletEipSameNameTest.java new file mode 100644 index 000000000000..22bea84e1275 --- /dev/null +++ b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletEipSameNameTest.java @@ -0,0 +1,80 @@ +/* + * 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. + */ +package org.apache.camel.component.kamelet; + +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit6.CamelTestSupport; +import org.junit.jupiter.api.Test; + +/** + * Kamelet EIPs with the same name and options each continue with their own nested steps (CAMEL-27262). + */ +public class KameletEipSameNameTest extends CamelTestSupport { + + @Test + public void testEachEipRunsItsOwnSteps() throws Exception { + getMockEndpoint("mock:a").expectedBodiesReceived("A"); + getMockEndpoint("mock:a").expectedHeaderReceived("foo", "bar"); + getMockEndpoint("mock:b").expectedBodiesReceived("B"); + getMockEndpoint("mock:b").expectedHeaderReceived("foo", "bar"); + + template.sendBody("direct:a", "A"); + template.sendBody("direct:b", "B"); + + MockEndpoint.assertIsSatisfied(context); + } + + @Test + public void testToKameletDoesNotRunTheStepsOfAnEip() throws Exception { + getMockEndpoint("mock:a").expectedMessageCount(0); + getMockEndpoint("mock:b").expectedMessageCount(0); + getMockEndpoint("mock:to").expectedBodiesReceived("C"); + getMockEndpoint("mock:to").expectedHeaderReceived("foo", "bar"); + + template.sendBody("direct:to", "C"); + + MockEndpoint.assertIsSatisfied(context); + } + + @Override + protected RoutesBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + routeTemplate("insert-header") + .templateParameter("value") + .from("kamelet:source") + .setHeader("foo", constant("{{value}}")) + .to("kamelet:sink"); + + from("direct:a").routeId("a") + .kamelet("insert-header?value=bar") + .to("mock:a"); + + from("direct:b").routeId("b") + .kamelet("insert-header?value=bar") + .to("mock:b"); + + from("direct:to").routeId("to") + .to("kamelet:insert-header?value=bar") + .to("mock:to"); + } + }; + } +}
