Skip to content

CAMEL-26135: camel-spring - a CamelEvent only goes to the spring-event consumers of the same name - #28576

Merged
davsclaus merged 2 commits into
apache:mainfrom
urunni88:CAMEL-26135-spring-event-name
Oct 28, 2026
Merged

davsclaus merged 2 commits into
apache:mainfrom
urunni88:CAMEL-26135-spring-event-name

Conversation

@urunni88

Copy link
Copy Markdown
Contributor

Description

CAMEL-26135: the name of a spring-event endpoint was ignored. A message sent to spring-event:foo was received by every spring-event consumer, also from("spring-event:bar").

The producer publishes a non-event body as a CamelEvent, whose source is the sending EventEndpoint. EventEndpoint.onApplicationEvent now skips a CamelEvent whose source has another name.

Other application events of the ApplicationContext (such as ContextRefreshedEvent, or an ApplicationEvent body sent by a producer) still go to every consumer, as the component docs say. I asked about this on the JIRA; happy to change it if a different behavior is wanted.

Changes:

  • EventEndpoint: the name check, and the consumer body description updated (generated JSON and catalog copy updated too)
  • EventRouteTest: a new test with a second route on spring-event:bar; it fails without the fix (mock:bar gets 2 messages) and passes with it
  • Upgrade guide 4.24: a note about the behavior change

Target

  • I checked that the commit is targeting the correct branch (Camel 4 uses the main branch)

Tracking

  • If this is a large change, bug fix, or code improvement, I checked there is a JIRA issue filed for the change (usually before you start working on it).

Apache Camel coding standards and style

  • 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.

AI-assisted contributions

  • 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 the help of Claude (Anthropic), credited with a Co-authored-by trailer in the commit.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. No issues found.

The fix is minimal and correct: EventEndpoint.onApplicationEvent() now filters CamelEvent instances by comparing the source endpoint name with this.name using Objects.equals (null-safe). Non-CamelEvent application events still broadcast to all consumers as documented.

Pre-fix validation: the new test correctly detects the regression — mock:bar.expectedMessageCount(1) would fail with 2 messages without the fix (bar would receive both the ContextRefreshedEvent and the CamelEvent from spring-event:foo). SpringTestSupport creates a fresh application context per @Test, so there's no state bleed between test methods.

Upgrade guide and both generated JSON catalog copies are properly updated.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@github-actions

Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • catalog/camel-catalog
  • components/camel-spring-parent/camel-spring-xml
  • components/camel-spring-parent/camel-spring
  • docs

ℹ️ Dependent modules were not tested because the total number of affected modules exceeded the threshold (50). Use the test-dependents label to force testing all dependents.


🔬 Scalpel shadow comparison — Scalpel: 23 of 708 tested, 25 compile-only — current: 240 all tested

Maveniverse Scalpel detected 23 affected modules (current approach: 240).

Skip-tests mode would test 23 modules (4 direct + 21 downstream), skip tests for 25 (generated code, meta-modules)

Modules only in current approach (217)
  • camel-a2a
  • camel-ai-observability
  • camel-as2
  • camel-asn1
  • camel-atmosphere-websocket
  • camel-avro
  • camel-avro-rpc
  • camel-aws-bedrock
  • camel-aws-cloudtrail
  • camel-aws-parameter-store
  • camel-aws-secrets-manager
  • camel-aws-security-hub
  • camel-aws2-athena
  • camel-aws2-comprehend
  • camel-aws2-cw
  • camel-aws2-ddb
  • camel-aws2-ec2
  • camel-aws2-ecs
  • camel-aws2-eks
  • camel-aws2-eventbridge
  • camel-aws2-iam
  • camel-aws2-kinesis
  • camel-aws2-kms
  • camel-aws2-lambda
  • camel-aws2-mq
  • camel-aws2-msk
  • camel-aws2-polly
  • camel-aws2-redshift
  • camel-aws2-rekognition
  • camel-aws2-s3
  • camel-aws2-s3-vectors
  • camel-aws2-ses
  • camel-aws2-sns
  • camel-aws2-sqs
  • camel-aws2-step-functions
  • camel-aws2-sts
  • camel-aws2-textract
  • camel-aws2-timestream
  • camel-aws2-translate
  • camel-azure-files
  • camel-barcode
  • camel-base64
  • camel-beanio
  • camel-bindy
  • camel-caffeine
  • camel-cbor
  • camel-clickup
  • camel-cm-sms
  • camel-crypto
  • camel-crypto-pgp
  • camel-csv
  • camel-cxf-rest
  • camel-cxf-soap
  • camel-cxf-spring-common
  • camel-cxf-spring-rest
  • camel-cxf-spring-transport
  • camel-cxf-transport
  • camel-datasonnet
  • camel-dhis2
  • camel-dns
  • camel-dynamic-router
  • camel-ehcache
  • camel-exec
  • camel-fastjson
  • camel-fhir
  • camel-file-watch
  • camel-flatpack
  • camel-fory
  • camel-freemarker
  • camel-ftp
  • camel-google-sheets
  • camel-google-vertexai
  • camel-graphql
  • camel-grok
  • camel-groovy
  • camel-gson
  • camel-hl7
  • camel-http
  • camel-huaweicloud-frs
  • camel-huaweicloud-imagerecognition
  • camel-huaweicloud-smn
  • camel-infinispan
  • camel-infinispan-embedded
  • camel-iso8583
  • camel-jackson
  • camel-jackson-avro
  • camel-jackson-protobuf
  • camel-jackson3
  • camel-jackson3-avro
  • camel-jackson3-protobuf
  • camel-jackson3xml
  • camel-jacksonxml
  • camel-jasypt
  • camel-java-joor-dsl
  • camel-jaxb
  • camel-jcache
  • camel-jdbc
  • camel-jetty
  • camel-jetty-common
  • camel-jooq
  • camel-jq
  • camel-jsch
  • camel-jsonapi
  • camel-jsonb
  • camel-jsonpath
  • camel-jta
  • camel-kafka
  • camel-kafka-common
  • camel-kafka-share
  • camel-kamelet
  • camel-keycloak
  • camel-knative-http
  • camel-kubernetes
  • camel-langchain4j-agent
  • camel-langchain4j-chat
  • camel-langchain4j-embeddings
  • camel-langchain4j-embeddingstore
  • camel-langchain4j-ingest
  • camel-lra
  • camel-lzf
  • camel-mcp-server
  • camel-mdc
  • camel-metrics
  • camel-micrometer
  • camel-micrometer-observability
  • camel-micrometer-prometheus
  • camel-microprofile-fault-tolerance
  • camel-mina
  • camel-minio
  • camel-mongodb
  • camel-mongodb-gridfs
  • camel-neo4j
  • camel-netty
  • camel-netty-http
  • camel-oaipmh
  • camel-oauth
  • camel-observability-services
  • camel-observation
  • camel-odata
  • camel-once
  • camel-openai
  • camel-openapi-java
  • camel-openapi-validator
  • camel-opentelemetry
  • camel-opentelemetry-metrics
  • camel-opentelemetry2
  • camel-optaplanner
  • camel-platform-http
  • camel-platform-http-jolokia
  • camel-platform-http-main
  • camel-platform-http-vertx
  • camel-pqc
  • camel-protobuf
  • camel-qdrant
  • camel-quartz
  • camel-quickfix
  • camel-resilience4j
  • camel-resilience4j-micrometer
  • camel-rest-openapi
  • camel-rest-postman
  • camel-restdsl-openapi-plugin
  • camel-salesforce
  • camel-salesforce-codegen
  • camel-salesforce-maven-plugin
  • camel-sap-netweaver
  • camel-saxon
  • camel-semantic
  • camel-semantic-openai
  • camel-semantic-typesafe-ai
  • camel-semantic-wolf-defender
  • camel-servlet
  • camel-slack
  • camel-smpp
  • camel-snakeyaml
  • camel-soap
  • camel-spring-ai-chat
  • camel-spring-batch
  • camel-spring-cloud-config
  • camel-spring-jdbc
  • camel-spring-ldap
  • camel-spring-rabbitmq
  • camel-spring-redis
  • camel-spring-security
  • camel-sql
  • camel-state-store
  • camel-stax
  • camel-swift
  • camel-syslog
  • camel-tarfile
  • camel-telegram
  • camel-telemetry
  • camel-telemetry-dev
  • camel-test-main-junit5
  • camel-test-main-junit6
  • camel-test-spring-junit5
  • camel-test-spring-junit6
  • camel-thrift
  • camel-thymeleaf
  • camel-tika
  • camel-tracing
  • camel-typesafe-ai
  • camel-undertow
  • camel-undertow-spring-security
  • camel-univocity-parsers
  • camel-velocity
  • camel-vertx-http
  • camel-webhook
  • camel-whatsapp
  • camel-xj
  • camel-xml-io-dsl
  • camel-xml-jaxb-dsl
  • camel-xml-jaxb-dsl-test-definition
  • camel-xml-jaxb-dsl-test-spring
  • camel-xmlsecurity
  • camel-xslt-saxon
  • camel-zipfile
  • camel-zookeeper-master
Modules Scalpel would test (23)
  • camel-activemq ← downstream of org.apache.camel:camel-jms
  • camel-activemq6 ← downstream of org.apache.camel:camel-jms
  • camel-amqp ← downstream of org.apache.camel:camel-jms
  • camel-consul ← downstream of org.apache.camel:camel-spring-main
  • camel-cxf-spring-soap ← downstream of org.apache.camel:camel-spring
  • camel-hazelcast ← downstream of org.apache.camel:camel-spring-main
  • camel-jbang-mcp ← downstream of org.apache.camel:camel-catalog
  • camel-jbang-plugin-mcp ← downstream of org.apache.camel:camel-jbang-core
  • camel-jbang-plugin-tui ← downstream of org.apache.camel:camel-catalog
  • camel-jbang-plugin-validate ← downstream of org.apache.camel:camel-yaml-dsl-validator
  • camel-jms ← downstream of org.apache.camel:camel-spring
  • camel-jpa ← downstream of org.apache.camel:camel-spring
  • camel-launcher-container ← downstream of org.apache.camel:camel-launcher
  • camel-mail ← downstream of org.apache.camel:camel-spring-main
  • camel-mail-microsoft-oauth ← downstream of org.apache.camel:camel-mail
  • camel-maven-plugin ← downstream of org.apache.camel:camel-spring-main
  • camel-spring ← components/camel-spring-parent/camel-spring/src/generated/resources/META-INF/org/apache/camel/component/event/spring-event.json, components/camel-spring-parent/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java
  • camel-spring-main ← downstream of org.apache.camel:camel-spring
  • camel-spring-ws ← downstream of org.apache.camel:camel-spring
  • camel-spring-xml ← components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/component/event/EventRouteTest.java, components/camel-spring-parent/camel-spring-xml/src/test/resources/org/apache/camel/component/event/camelContext.xml, components/camel-spring-parent/camel-spring-xml/src/test/resources/org/apache/camel/component/event/mistypedPackage.xml
  • camel-yaml-dsl-validator ← downstream of org.apache.camel:camel-catalog
  • camel-yaml-dsl-validator-maven-plugin ← downstream of org.apache.camel:camel-yaml-dsl-validator
  • camel-zookeeper ← downstream of org.apache.camel:camel-spring-main
Modules with tests skipped (25)
  • apache-camel
  • camel-allcomponents
  • camel-catalog-console
  • camel-catalog-maven
  • camel-catalog-suggest
  • camel-componentdsl
  • camel-endpointdsl
  • camel-endpointdsl-support
  • camel-itest
  • camel-jbang-core
  • camel-jbang-it
  • camel-jbang-main
  • camel-jbang-plugin-edit
  • camel-jbang-plugin-generate
  • camel-jbang-plugin-kubernetes
  • camel-jbang-plugin-test
  • camel-kamelet-main
  • camel-launcher
  • camel-report-maven-plugin
  • camel-route-parser
  • camel-yaml-dsl
  • camel-yaml-dsl-deserializers
  • camel-yaml-dsl-maven-plugin
  • coverage
  • dummy-component

ℹ️ Shadow mode — Scalpel observes but does not affect test execution. Learn more

Build reactor — dependencies compiled but only changed modules were tested (4 modules, 53.7s total)

Total reactor time: 53.7s

Module Duration Status
Camel :: Catalog :: Camel Catalog 27.4s SUCCESS
Camel :: Docs 18.9s SUCCESS
Camel :: Spring 7.4s SUCCESS
Camel :: Spring XML n/a

Top 20 slowest modules:

  • Camel :: Catalog :: Camel Catalog (27.4s)
  • Camel :: Docs (18.9s)
  • Camel :: Spring (7.4s)

⚙️ View full build and test results

@davsclaus

Copy link
Copy Markdown
Contributor

The build (21, false) check fails on the new test, in a subclass:

MistypedPackageTest>EventRouteTest.testCamelEventOnlyGoesToEndpointWithSameName:70
mock://bar Received message count. Expected: <1> but was: <0>

MistypedPackageTest extends EventRouteTest, so it inherits testCamelEventOnlyGoesToEndpointWithSameName. But it loads mistypedPackage.xml, which has no spring-event:bar route, so mock:bar never gets a message. It fails every run, so this is not a flaky test.

The simplest fix is to add the same route to components/camel-spring-parent/camel-spring-xml/src/test/resources/org/apache/camel/component/event/mistypedPackage.xml, so the subclass still runs the full suite:

<route>
    <from uri="spring-event:bar"/>
    <to uri="mock:bar"/>
</route>

The change to EventEndpoint looks good.

Claude Code on behalf of davsclaus

@urunni88

Copy link
Copy Markdown
Contributor Author

Thanks @davsclaus! I added the spring-event:bar route to mistypedPackage.xml. EventRouteTest and MistypedPackageTest now pass locally (4 tests).

@oscerd oscerd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct bugfix. A spring-event producer wraps a non-ApplicationEvent body in a CamelEvent and publishes it to the Spring ApplicationContext, where every spring-event consumer's onApplicationEvent received it — so a body sent to spring-event:foo also reached from("spring-event:bar"), cross-talk between unrelated endpoints. Skipping a CamelEvent whose source endpoint name doesn't match this endpoint's name (Objects.equals(name, camelEvent.getSource().getName()), null-safe) scopes it correctly, while genuine ApplicationContext events (ContextRefreshedEvent, or an ApplicationEvent body) still broadcast to every consumer — the right line to draw.

The test nails it: spring-event:foo producing → mock:result (from foo) gets the context-refreshed event + the CamelEvent (2), while mock:bar (from bar) gets only the context-refreshed event (1), and both test contexts gain the :bar route. The upgrade guide documents the scoping change.

No blockers.

Claude Code on behalf of oscerd

urunni88 and others added 2 commits October 28, 2026 19:20
…t consumers of the same name

The consumer now skips a CamelEvent sent by a spring-event producer with another name. Other application events still go to every consumer.

Co-authored-by: Claude <noreply@anthropic.com>
MistypedPackageTest extends EventRouteTest and runs the new test with its own routes.

Co-authored-by: Claude <noreply@anthropic.com>
@urunni88
urunni88 force-pushed the CAMEL-26135-spring-event-name branch from 350cbb3 to 3934adb Compare October 28, 2026 13:51
@davsclaus davsclaus added this to the 4.24.0 milestone Oct 28, 2026
@davsclaus davsclaus added the bug Something isn't working label Oct 28, 2026
@davsclaus
davsclaus merged commit 0122749 into apache:main Oct 28, 2026
7 checks passed
@urunni88
urunni88 deleted the CAMEL-26135-spring-event-name branch October 28, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants