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 012274993a9b CAMEL-26135: camel-spring - a CamelEvent only goes to the 
spring-event consumers of the same name (#28576)
012274993a9b is described below

commit 012274993a9bd715855ff0fcfa073bfe1be0b974
Author: Urmila Unni <[email protected]>
AuthorDate: Wed Oct 28 21:35:08 2026 +0530

    CAMEL-26135: camel-spring - a CamelEvent only goes to the spring-event 
consumers of the same name (#28576)
    
    A CamelEvent is only delivered to the spring-event consumers of the same 
endpoint name instead of all of them. Documented in the 4.24 upgrade guide.
    
    Co-Authored-By: Claude <[email protected]>
---
 .../org/apache/camel/catalog/components/spring-event.json |  2 +-
 .../org/apache/camel/component/event/EventRouteTest.java  | 15 +++++++++++++++
 .../org/apache/camel/component/event/camelContext.xml     |  4 ++++
 .../org/apache/camel/component/event/mistypedPackage.xml  |  4 ++++
 .../org/apache/camel/component/event/spring-event.json    |  2 +-
 .../org/apache/camel/component/event/EventEndpoint.java   | 15 +++++++++++----
 .../modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc   | 10 ++++++++++
 7 files changed, 46 insertions(+), 6 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/spring-event.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/spring-event.json
index a90da06950b1..d2a2714af54e 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/spring-event.json
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/spring-event.json
@@ -29,7 +29,7 @@
     "autowiredEnabled": { "index": 2, "kind": "property", "displayName": 
"Autowired Enabled", "group": "advanced", "label": "advanced", "required": 
false, "type": "boolean", "javaType": "boolean", "deprecated": false, 
"autowired": false, "secret": false, "defaultValue": true, "description": 
"Whether autowiring is enabled. This is used for automatic autowiring options 
(the option must be marked as autowired) by looking up in the registry to find 
if there is a single instance of matching t [...]
   },
   "bodyTypes": {
-    "consumerOut": { "carriers": [ "pojo" ], "javaType": 
"org.springframework.context.ApplicationEvent", "description": "The 
ApplicationEvent itself, for every event of the ApplicationContext whatever the 
name: an object published with publishEvent comes as a PayloadApplicationEvent, 
and a non-event body a spring-event producer sent as a CamelEvent, whose 
getExchange() holds the sending exchange" },
+    "consumerOut": { "carriers": [ "pojo" ], "javaType": 
"org.springframework.context.ApplicationEvent", "description": "The 
ApplicationEvent itself, for every event of the ApplicationContext: an object 
published with publishEvent comes as a PayloadApplicationEvent, and a non-event 
body a spring-event producer sent as a CamelEvent, whose getExchange() holds 
the sending exchange. A CamelEvent only goes to the consumers of the endpoint 
with the same name" },
     "producerIn": { "carriers": [ "any" ], "description": "An ApplicationEvent 
body is published as it is. Any other body, also none, is published as a 
CamelEvent that holds the exchange, so listeners read the body from its 
getExchange()" },
     "producerOut": { "carriers": [ "unchanged" ], "description": "The body is 
left as it is. The listeners run before the producer returns, and a CamelEvent 
gives them the exchange itself" }
   },
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/component/event/EventRouteTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/component/event/EventRouteTest.java
index be7a1777d35e..579855f468f4 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/component/event/EventRouteTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/component/event/EventRouteTest.java
@@ -56,6 +56,21 @@ public class EventRouteTest extends SpringTestSupport {
         assertEquals(expectedBody, actualBody, "Received event body");
     }
 
+    @Test
+    public void testCamelEventOnlyGoesToEndpointWithSameName() throws 
Exception {
+        MockEndpoint result = resolveMandatoryEndpoint("mock:result", 
MockEndpoint.class);
+        result.expectedMessageCount(2);
+        // bar gets the ContextRefreshedEvent, but not the CamelEvent sent to 
spring-event:foo
+        MockEndpoint bar = resolveMandatoryEndpoint("mock:bar", 
MockEndpoint.class);
+        bar.expectedMessageCount(1);
+
+        template.sendBody(uri, expectedBody);
+
+        result.assertIsSatisfied();
+        bar.assertIsSatisfied();
+        
assertNotNull(bar.getReceivedExchanges().get(0).getIn().getBody(ContextRefreshedEvent.class));
+    }
+
     @Override
     protected AbstractXmlApplicationContext createApplicationContext() {
         return new 
ClassPathXmlApplicationContext("org/apache/camel/component/event/camelContext.xml");
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/resources/org/apache/camel/component/event/camelContext.xml
 
b/components/camel-spring-parent/camel-spring-xml/src/test/resources/org/apache/camel/component/event/camelContext.xml
index 69723eea588f..476470613e68 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/resources/org/apache/camel/component/event/camelContext.xml
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/resources/org/apache/camel/component/event/camelContext.xml
@@ -32,6 +32,10 @@
       <from uri="spring-event:foo"/>
       <to uri="mock:result"/>
     </route>
+    <route>
+      <from uri="spring-event:bar"/>
+      <to uri="mock:bar"/>
+    </route>
   </camelContext>
 
 </beans>
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/resources/org/apache/camel/component/event/mistypedPackage.xml
 
b/components/camel-spring-parent/camel-spring-xml/src/test/resources/org/apache/camel/component/event/mistypedPackage.xml
index 64bba5961ca6..1cbe658280cd 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/resources/org/apache/camel/component/event/mistypedPackage.xml
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/resources/org/apache/camel/component/event/mistypedPackage.xml
@@ -36,6 +36,10 @@
             <from uri="spring-event:foo"/>
             <to uri="mock:result"/>
         </route>
+        <route>
+            <from uri="spring-event:bar"/>
+            <to uri="mock:bar"/>
+        </route>
     </camelContext>
 
 </beans>
diff --git 
a/components/camel-spring-parent/camel-spring/src/generated/resources/META-INF/org/apache/camel/component/event/spring-event.json
 
b/components/camel-spring-parent/camel-spring/src/generated/resources/META-INF/org/apache/camel/component/event/spring-event.json
index a90da06950b1..d2a2714af54e 100644
--- 
a/components/camel-spring-parent/camel-spring/src/generated/resources/META-INF/org/apache/camel/component/event/spring-event.json
+++ 
b/components/camel-spring-parent/camel-spring/src/generated/resources/META-INF/org/apache/camel/component/event/spring-event.json
@@ -29,7 +29,7 @@
     "autowiredEnabled": { "index": 2, "kind": "property", "displayName": 
"Autowired Enabled", "group": "advanced", "label": "advanced", "required": 
false, "type": "boolean", "javaType": "boolean", "deprecated": false, 
"autowired": false, "secret": false, "defaultValue": true, "description": 
"Whether autowiring is enabled. This is used for automatic autowiring options 
(the option must be marked as autowired) by looking up in the registry to find 
if there is a single instance of matching t [...]
   },
   "bodyTypes": {
-    "consumerOut": { "carriers": [ "pojo" ], "javaType": 
"org.springframework.context.ApplicationEvent", "description": "The 
ApplicationEvent itself, for every event of the ApplicationContext whatever the 
name: an object published with publishEvent comes as a PayloadApplicationEvent, 
and a non-event body a spring-event producer sent as a CamelEvent, whose 
getExchange() holds the sending exchange" },
+    "consumerOut": { "carriers": [ "pojo" ], "javaType": 
"org.springframework.context.ApplicationEvent", "description": "The 
ApplicationEvent itself, for every event of the ApplicationContext: an object 
published with publishEvent comes as a PayloadApplicationEvent, and a non-event 
body a spring-event producer sent as a CamelEvent, whose getExchange() holds 
the sending exchange. A CamelEvent only goes to the consumers of the endpoint 
with the same name" },
     "producerIn": { "carriers": [ "any" ], "description": "An ApplicationEvent 
body is published as it is. Any other body, also none, is published as a 
CamelEvent that holds the exchange, so listeners read the body from its 
getExchange()" },
     "producerOut": { "carriers": [ "unchanged" ], "description": "The body is 
left as it is. The listeners run before the producer returns, and a CamelEvent 
gives them the exchange itself" }
   },
diff --git 
a/components/camel-spring-parent/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java
 
b/components/camel-spring-parent/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java
index 4337c59e4719..c6cb4d7032f9 100644
--- 
a/components/camel-spring-parent/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java
+++ 
b/components/camel-spring-parent/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.event;
 
+import java.util.Objects;
+
 import org.apache.camel.Category;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
@@ -43,10 +45,11 @@ import static 
org.apache.camel.RuntimeCamelException.wrapRuntimeCamelException;
 @UriEndpoint(firstVersion = "1.4.0", scheme = "spring-event", title = "Spring 
Event", syntax = "spring-event:name",
              remote = false, category = { Category.MESSAGING })
 @BodyTypes(consumerOut = @BodyType(value = Carrier.POJO, javaType = 
"org.springframework.context.ApplicationEvent",
-                                   description = "The ApplicationEvent itself, 
for every event of the ApplicationContext"
-                                                 + " whatever the name: an 
object published with publishEvent comes as a"
-                                                 + " PayloadApplicationEvent, 
and a non-event body a spring-event producer"
-                                                 + " sent as a CamelEvent, 
whose getExchange() holds the sending exchange"),
+                                   description = "The ApplicationEvent itself, 
for every event of the ApplicationContext:"
+                                                 + " an object published with 
publishEvent comes as a PayloadApplicationEvent,"
+                                                 + " and a non-event body a 
spring-event producer sent as a CamelEvent, whose"
+                                                 + " getExchange() holds the 
sending exchange. A CamelEvent only goes to the"
+                                                 + " consumers of the endpoint 
with the same name"),
            producerIn = @BodyType(value = Carrier.ANY,
                                   description = "An ApplicationEvent body is 
published as it is. Any other body, also none,"
                                                 + " is published as a 
CamelEvent that holds the exchange, so listeners read the"
@@ -109,6 +112,10 @@ public class EventEndpoint extends DefaultEndpoint 
implements ApplicationContext
     }
 
     public void onApplicationEvent(ApplicationEvent event) {
+        // a CamelEvent is only for consumers on the endpoint with the same 
name
+        if (event instanceof CamelEvent camelEvent && !Objects.equals(name, 
camelEvent.getSource().getName())) {
+            return;
+        }
         Exchange exchange = createExchange();
         exchange.getIn().setBody(event);
         try {
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 37b78c4c1045..e980806ecabb 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
@@ -3940,3 +3940,13 @@ version, with a warning. When the CLI is newer than all 
the releases, or the rel
 
 `--version` and `--gav` are used as given, with a warning when the release is 
built for another Camel version. Plugins
 registered before are not changed. See 
xref:camel-jbang-projects.adoc#_plugin_versions[Plugin versions].
+
+=== camel-spring - a CamelEvent only goes to the consumers of the same name
+
+A `spring-event` producer publishes a body that is not an `ApplicationEvent` 
as a `CamelEvent`. Before, every
+`spring-event` consumer received it, whatever its name. Now only the consumers 
of the endpoint with the same name
+receive it: a message sent to `spring-event:foo` goes to 
`from("spring-event:foo")`, and no longer to
+`from("spring-event:bar")`.
+
+Other application events of the `ApplicationContext`, such as 
`ContextRefreshedEvent` or an `ApplicationEvent` body
+published by a producer, still go to every consumer.

Reply via email to