Skip to content

CAMEL-25278: camel-cometd - a stopped consumer must stop listening to its channel, and the server extensions and listeners must be registered once - #27307

Merged
davsclaus merged 1 commit into
apache:mainfrom
allthingssecurity:camel-cometd-consumer-stop-and-extensions
Oct 3, 2026
Merged

davsclaus merged 1 commit into
apache:mainfrom
allthingssecurity:camel-cometd-consumer-stop-and-extensions

Conversation

@allthingssecurity

Copy link
Copy Markdown
Contributor

Description

CAMEL-25278

The producers and consumers of a host and port share one CometD server, which is only stopped with the last of them:

  • CometdConsumer added its service (a listener of the channel) on start and never removed it. When the server outlived the consumer (a producer, or another consumer, on the same host and port), the stopped consumer kept calling the processor of the route: after a restart of the route each message was processed twice, once more per restart.
  • CometdComponent.connect added the configured extensions and server listeners to the server for every producer and consumer that connected, so with a producer and a consumer on the same host and port each one was called twice per message or session, and once more after each restart.

This change: the consumer removes its service from the channel and disconnects its local session on stop; the component sets the security policy and adds the extensions and server listeners only when it creates the server.

Tests:

  • CometdConsumerRestartTest (new, 3 tests): a producer route and a consumer route on the same host and port; restart of the consumer route then one message; a SessionListener and one new session; a stopped consumer route (control, passes without the change too).
  • Without the change 2 fail: mock://test Received message count. Expected: <1> but was: <2>, and expected: <1> but was: <2> for the listener.
  • With the change all camel-cometd tests pass: 26 tests, 0 failures.

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.
    (I built and tested the affected module, including the formatter and import-sort plugins. I did not run the full root build.)

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 Claude Code (Claude Opus 5.5). The commit carries a Co-Authored-By trailer.

Claude Code on behalf of allthingssecurity

🤖 Generated with Claude Code

… its channel, and the server extensions and listeners must be registered once

The producers and consumers of a host and port share one CometD server,
which is only stopped with the last of them.

- CometdConsumer registered its service (a listener of the channel) on start
  and never removed it. When the server outlived the consumer (a producer or
  another consumer on the same host and port), the stopped consumer kept
  processing the messages of the channel: after a restart of the route each
  message was processed twice, once more per restart. The consumer now
  removes the service and disconnects its local session on stop.

- CometdComponent.connect added the configured extensions and server
  listeners to the server for every producer and consumer that connected, so
  with a producer and a consumer on the same host and port each extension
  and listener was called twice for every message or session, and once more
  after each restart. They are now registered once, when the server is
  created.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 3, 2026

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.

@davsclaus davsclaus 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. The consumer now removes its service and disconnects its session on stop, and the extensions and listeners are registered only when the shared server is created. Both bugs are real, and the restart and listener tests cover them.

Possible follow-up for a separate JIRA: CometdProducer keeps its ProducerService (bound to the old server's local session) across a stop/start that recreates the server. It's the same pattern as the consumer fix here.

Claude Code on behalf of davsclaus. This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • components/camel-cometd

🔬 Scalpel shadow comparison — Scalpel: 9 of 698 tested, 27 compile-only — current: 9 all tested

Maveniverse Scalpel detected 9 affected modules (current approach: 9).

Skip-tests mode would test 9 modules (1 direct + 8 downstream), skip tests for 27 (generated code, meta-modules)

Modules Scalpel would test (9)
  • camel-cometd ← components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdComponent.java, components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdConsumer.java, components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdConsumerRestartTest.java
  • 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-route-parser ← downstream of org.apache.camel:camel-route-parser
  • 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-launcher-container ← downstream of org.apache.camel:camel-launcher
  • 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
Modules with tests skipped (27)
  • apache-camel
  • camel-allcomponents
  • camel-catalog
  • 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
  • docs
  • dummy-component

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

All tested modules (36 modules, 5m 41s total)

Total reactor time: 5m 41s

Module Duration Status
Camel :: Launcher 47.1s SUCCESS
Camel :: JBang :: Plugin :: TUI 41.7s SUCCESS
Camel :: JBang :: MCP 37.7s SUCCESS
Camel :: Component DSL 32.1s SUCCESS
Camel :: Catalog :: Camel Catalog 22.4s SUCCESS
Camel :: YAML DSL :: Validator 18.9s SUCCESS
Camel :: YAML DSL 17.9s SUCCESS
Camel :: JBang :: Plugin :: Kubernetes 17.9s SUCCESS
Camel :: Cometd 15.6s SUCCESS
Camel :: Docs 14.1s SUCCESS
Camel :: Kamelet Main 11.2s SUCCESS
Camel :: YAML DSL :: Deserializers 7.7s SUCCESS
Camel :: Catalog :: Camel Route Parser 7.6s SUCCESS
Camel :: JBang :: Plugin :: Testing 7.5s SUCCESS
Camel :: Catalog :: Camel Report Maven Plugin 5.9s SUCCESS
Camel :: JBang :: Plugin :: Validate 5.2s SUCCESS
Camel :: YAML DSL :: Validator Maven Plugin 4.9s SUCCESS
Camel :: All Components Sync point 4.8s SUCCESS
Camel :: YAML DSL :: Maven Plugins 3.5s SUCCESS
Camel :: Catalog :: Maven 2.7s SUCCESS
Camel :: Catalog :: Suggest (deprecated) 2.4s SUCCESS
Camel :: Assembly 2.0s SUCCESS
Camel :: Coverage 1.5s SUCCESS
Camel :: JBang :: Plugin :: Edit 1.3s SUCCESS
Camel :: Catalog :: Dummy Component 1.2s SUCCESS
Camel :: JBang :: Plugin :: Generate 1.1s SUCCESS
Camel :: Endpoint DSL :: Support 0.8s SUCCESS
Camel :: JBang :: Integration tests 0.8s SUCCESS
Camel :: Catalog :: Console 0.8s SUCCESS
Camel :: JBang :: Main 0.8s SUCCESS
Camel :: JBang :: Plugin :: MCP 0.7s SUCCESS
Camel :: Launcher :: Container 0.6s SUCCESS
Camel :: JBang :: Plugin :: Route Parser 0.5s SUCCESS
Camel :: Endpoint DSL n/a
Camel :: Integration Tests n/a
Camel :: JBang :: Core n/a

Top 20 slowest modules:

  • Camel :: Launcher (47.1s)
  • Camel :: JBang :: Plugin :: TUI (41.7s)
  • Camel :: JBang :: MCP (37.7s)
  • Camel :: Component DSL (32.1s)
  • Camel :: Catalog :: Camel Catalog (22.4s)
  • Camel :: YAML DSL :: Validator (18.9s)
  • Camel :: YAML DSL (17.9s)
  • Camel :: JBang :: Plugin :: Kubernetes (17.9s)
  • Camel :: Cometd (15.6s)
  • Camel :: Docs (14.1s)
  • Camel :: Kamelet Main (11.2s)
  • Camel :: YAML DSL :: Deserializers (7.7s)
  • Camel :: Catalog :: Camel Route Parser (7.6s)
  • Camel :: JBang :: Plugin :: Testing (7.5s)
  • Camel :: Catalog :: Camel Report Maven Plugin (5.9s)
  • Camel :: JBang :: Plugin :: Validate (5.2s)
  • Camel :: YAML DSL :: Validator Maven Plugin (4.9s)
  • Camel :: All Components Sync point (4.8s)
  • Camel :: YAML DSL :: Maven Plugins (3.5s)
  • Camel :: Catalog :: Maven (2.7s)

⚙️ View full build and test results

@davsclaus davsclaus added this to the 4.23.0 milestone Oct 3, 2026
@davsclaus davsclaus added the bug Something isn't working label Oct 3, 2026
@davsclaus
davsclaus merged commit 5f96f71 into apache:main Oct 3, 2026
6 checks passed
@allthingssecurity
allthingssecurity deleted the camel-cometd-consumer-stop-and-extensions branch October 3, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants