allthingssecurity opened a new pull request, #27305: URL: https://github.com/apache/camel/pull/27305
# Description [CAMEL-25276](https://issues.apache.org/jira/browse/CAMEL-25276) A PubNub client hands every message and presence event to all its listeners, whatever the channel, and since CAMEL-16142 one client can be shared by all `pubnub:` endpoints (autowired, or `pubnub=#bean`): - **Cross-talk.** The consumer's `SubscribeCallback` did not look at the channel, so with a shared client each route also received the messages of the other routes' channels. - **Duplicates after a restart.** The consumer added a new callback on every start and resume and never removed it. The endpoint and its client survive a route stop, so after a stop and start every message was received twice, once more per restart (also without a shared client). - **Removing a route destroyed the shared client.** `PubNubEndpoint.doStop` destroyed the client also when it came from the registry; removing a route removes the endpoints only it uses, so the other routes and producers lost their client. This change: - `PubNubConsumer` keeps its callback and removes it when it stops or is suspended, and ignores events whose channel (or wildcard subscription) is not one of its channels (a comma separated channel option, which the client subscribes to as separate channels, is matched per channel). Presence events carry the channel without `-pnpres`, so the same check applies. - `PubNubEndpoint` destroys only a client it created itself. - The upgrade guide for 4.23 gets a note. Tests: - `PubNubConsumerListenerTest` (new, 7 tests). It uses a real PubNub client (a subclass of `PubNubForJavaImpl` that counts `destroy()` calls) and hands messages to its listeners through the client's `ListenerManager`, as the subscribe loop does, so no subscribe response is needed. - Without the change four fail: the other channel's route receives the message (`Expected: <0> but was: <1>`), a message is received twice after a restart (`Expected: <1> but was: <2>`), removing a route destroys the shared client (`expected: <0> but was: <1>`), and a message of a wildcard subscription (`news.*`) and a presence event reach the other route too. The three other tests (comma separated channels, no message after stop, the endpoint still destroys a client it created) are guards and pass on main too. - With the change all camel-pubnub tests pass: 21 tests, 0 failures. # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it). # Apache Camel coding standards and style - [x] 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 - [x] 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](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
