CAMEL-25278: camel-cometd - a stopped consumer must stop listening to its channel, and the server extensions and listeners must be registered once - #27307
Conversation
… 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>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
davsclaus
left a comment
There was a problem hiding this comment.
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.
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 9 of 698 tested, 27 compile-only — current: 9 all testedMaveniverse 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)
Modules with tests skipped (27)
All tested modules (36 modules, 5m 41s total)Total reactor time: 5m 41s
Top 20 slowest modules:
|
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:
CometdConsumeradded 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.connectadded 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; aSessionListenerand one new session; a stopped consumer route (control, passes without the change too).mock://test Received message count. Expected: <1> but was: <2>, andexpected: <1> but was: <2>for the listener.Target
mainbranch)Tracking
Apache Camel coding standards and style
mvn clean install -DskipTestslocally 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
Co-authored-bytrailers) 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-Bytrailer.Claude Code on behalf of allthingssecurity
🤖 Generated with Claude Code