This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 7780f3e543e2 CAMEL-27261: camel-kamelet - each Kamelet EIP has a 
Kamelet route of its own (#30456)
7780f3e543e2 is described below

commit 7780f3e543e240767eade2b02a41065ba33d9c1b
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Nov 20 07:21:58 2026 +0100

    CAMEL-27261: camel-kamelet - each Kamelet EIP has a Kamelet route of its 
own (#30456)
    
    A Kamelet EIP got its endpoint from the endpoint registry, so Kamelet EIPs
    with the same name and options, and a to("kamelet:...") with them, shared
    one endpoint, one Kamelet route and one callback key in the component: the
    messages of one route continued with the nested steps of the last such EIP
    created, and a to("kamelet:...") ran them too.
    
    The Kamelet EIP now uses a prototype endpoint of its own, so it has its
    own Kamelet route and callback key, and shuts the endpoint down with it,
    which removes that route when the route of the EIP is removed.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../camel/component/kamelet/KameletProcessor.java  |  12 ++-
 .../kamelet/KameletEipSameOptionsTest.java         | 111 +++++++++++++++++++++
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc    |   9 ++
 3 files changed, 131 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..0fb2fdc2bfec 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
@@ -23,6 +23,7 @@ import org.apache.camel.AsyncCallback;
 import org.apache.camel.AsyncProcessor;
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
+import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Navigate;
 import org.apache.camel.Processor;
@@ -46,6 +47,9 @@ public class KameletProcessor extends BaseProcessorSupport
     private final AsyncProcessor processor;
     private final String parentRouteId;
     private final String parentProcessorId;
+    // an endpoint of this Kamelet EIP only (a prototype endpoint, not the one 
the uri shares): its own Kamelet route
+    // and its own callback key, so the kamelet:sink of that route continues 
with the steps of this EIP only
+    private Endpoint endpoint;
     private KameletProducer producer;
     private KameletComponent component;
     private CamelContext camelContext;
@@ -134,7 +138,11 @@ 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();
+                // Two Kamelet EIPs with the same name and options, or a 
to("kamelet:...") with them, would otherwise
+                // share one endpoint, so one Kamelet route and one callback 
key, and the last EIP registered would
+                // get the messages of the others
+                this.endpoint = 
camelContext.getCamelContextExtension().getPrototypeEndpoint("kamelet://" + 
name);
+                this.producer = (KameletProducer) 
endpoint.createAsyncProducer();
             } catch (Exception e) {
                 throw new RuntimeException(e);
             }
@@ -175,5 +183,7 @@ public class KameletProcessor extends BaseProcessorSupport
     protected void doShutdown() throws Exception {
         ServiceHelper.stopAndShutdownServices(processor, producer);
         component.removeKameletEip(producer.getKey());
+        // the endpoint removes the Kamelet route it created for this EIP
+        ServiceHelper.stopAndShutdownService(endpoint);
     }
 }
diff --git 
a/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletEipSameOptionsTest.java
 
b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletEipSameOptionsTest.java
new file mode 100644
index 000000000000..38aa6c6e9c36
--- /dev/null
+++ 
b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletEipSameOptionsTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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 java.util.concurrent.TimeUnit;
+
+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;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Kamelet EIPs with the same name and options each continue with their own 
steps, and a to("kamelet:...") with the same
+ * name and options does not run the steps of an EIP.
+ */
+class KameletEipSameOptionsTest extends CamelTestSupport {
+
+    @Test
+    void eachKameletEipContinuesWithItsOwnSteps() throws Exception {
+        getMockEndpoint("mock:b1-nested").expectedBodiesReceived("from-b1");
+        getMockEndpoint("mock:b2-nested").expectedBodiesReceived("from-b2");
+
+        template.sendBody("direct:b1", "from-b1");
+        template.sendBody("direct:b2", "from-b2");
+
+        MockEndpoint.assertIsSatisfied(context);
+    }
+
+    @Test
+    void toKameletDoesNotRunTheStepsOfAKameletEip() throws Exception {
+        getMockEndpoint("mock:a").expectedBodiesReceived("from-a");
+        getMockEndpoint("mock:a").expectedHeaderReceived("action", "done");
+        getMockEndpoint("mock:b1-nested").expectedMessageCount(0);
+        getMockEndpoint("mock:b2-nested").expectedMessageCount(0);
+
+        template.sendBody("direct:a", "from-a");
+
+        MockEndpoint.assertIsSatisfied(context);
+    }
+
+    @Test
+    void removingTheRouteOfAKameletEipRemovesItsKameletRoute() throws 
Exception {
+        int before = context.getRoutes().size();
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:c").routeId("c")
+                        .kamelet("my-action?value=done")
+                        .to("mock:c-nested")
+                        .end();
+            }
+        });
+        // the route and the Kamelet route of its EIP
+        assertEquals(before + 2, context.getRoutes().size());
+
+        getMockEndpoint("mock:c-nested").expectedBodiesReceived("from-c");
+        template.sendBody("direct:c", "from-c");
+        MockEndpoint.assertIsSatisfied(context);
+
+        context.getRouteController().stopRoute("c");
+        context.removeRoute("c");
+        // the Kamelet route of the EIP is removed with it, a moment later
+        await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> 
assertEquals(before, context.getRoutes().size()));
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                routeTemplate("my-action")
+                        .templateParameter("value")
+                        .from("kamelet:source")
+                        .setHeader("action", constant("{{value}}"))
+                        .to("kamelet:sink");
+
+                from("direct:b1").routeId("b1")
+                        .kamelet("my-action?value=done")
+                        .to("mock:b1-nested")
+                        .end();
+
+                from("direct:b2").routeId("b2")
+                        .kamelet("my-action?value=done")
+                        .to("mock:b2-nested")
+                        .end();
+
+                from("direct:a").routeId("a")
+                        .to("kamelet:my-action?value=done")
+                        .to("mock:a");
+            }
+        };
+    }
+}
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 8940732dceab..d51eef60e2eb 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -228,6 +228,15 @@ is binary already and can be read again, and a source 
Kamelet such as `aws-s3-so
 declares `binary` and gives the object as a stream, which may be large. Any 
other body, including an `InputStream` that is
 not a stream cache (stream caching turned off), is still converted to a 
`byte[]`.
 
+=== camel-kamelet - each Kamelet EIP has a Kamelet route of its own
+
+Kamelet EIPs (`kamelet` with nested steps) with the same name and options used 
to share one Kamelet route, and with it
+the steps to continue with: the messages of one route ran the nested steps of 
the last such EIP that was created, and a
+`to("kamelet:...")` with the same name and options also ran them. Each Kamelet 
EIP now creates a Kamelet route of its own
+and continues with its own steps. An application with several Kamelet EIPs 
with the same name and options therefore has
+one Kamelet route per EIP (for example `my-action-1`, `my-action-2`) where it 
had one before. When a route with a Kamelet
+EIP is removed while the context runs, its Kamelet route is removed with it.
+
 === camel-core-model - doTry keeps doCatch and doFinally in its outputs
 
 `doCatch` and `doFinally` written as properties of `doTry` in the YAML DSL are 
now kept in the outputs of the

Reply via email to