Skip to content

CAMEL-24569: Support Salesforce Streaming API disconnect messages - #25908

Merged
davsclaus merged 3 commits into
apache:mainfrom
bartoszpop:CAMEL-24569-salesforce-streaming-api-disconnect-messages
Aug 31, 2026
Merged

CAMEL-24569: Support Salesforce Streaming API disconnect messages#25908
davsclaus merged 3 commits into
apache:mainfrom
bartoszpop:CAMEL-24569-salesforce-streaming-api-disconnect-messages

Conversation

@bartoszpop

Copy link
Copy Markdown
Contributor

CAMEL-24569: Support Salesforce Streaming API disconnect messages

Description

Handle server-initiated /meta/disconnect messages introduced in Salesforce Streaming API 64.0 and reconnect to keep subscriptions active.

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.

Bartosz Popiela added 2 commits August 31, 2026 00:23
Handle server-initiated /meta/disconnect messages introduced in
Salesforce Streaming API 64.0 and reconnect to keep subscriptions active.
…ssing a disconnect message

- Wait for CometD to reach the disconnected state before reconnecting.
- Use the managed executor and verify that channels are resubscribed only once.

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

Reviewed against the project's contribution rules and build/test conventions (not a substitute for CodeRabbit/Sourcery/SonarCloud or other specialized static analysis).

Verification performed: built camel-salesforce-component from this branch (mvn install -DskipTests — clean). Ran the project's own formatter (mvn formatter:format impsort:sort) and it produced zero diff — the large amount of line-rewrapping in this diff looked at first glance like it might be from a different formatter/IDE config than the project's, but it's actually exactly what Camel's own formatter produces, so it's legitimate fallout of the mandated mvn clean install -DskipTests step, not scope drift. Ran SubscriptionHelperManualIT (a self-contained stub-server test — it only executes under the integration Maven profile, not default CI, despite the name) directly via surefire: the new shouldResubscribeOnDisconnectMessage test passes. One other test in the same class, shouldResubscribeOnSubscriptionFailure, fails — I confirmed by running the identical test against unmodified main that this is a pre-existing failure unrelated to this PR (an NPE from an unstubbed mock), not a regression introduced here.

I also compared the two commits: the first pass used a while loop with Thread.sleep() for reconnect backoff, and the second commit ("Improve Salesforce component to be state-safe...") replaced it with a waitFor(..., DISCONNECTED) check that delegates back into the existing handshake/backoff machinery. That's a good self-correction, and it fits well with this file's history of hardening against races (CAMEL-23391, CAMEL-24160/24161, CAMEL-24272) — appreciate that the reconnect logic reuses the established resubscribe-on-handshake path rather than reimplementing it.

No blocking issues found. Two non-blocking questions below (see inline comments), plus one process note: JIRA CAMEL-24569 is currently Unassigned/Open — per project convention it should be assigned to the contributor and moved to "In Progress" before merge.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

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

@gnodet gnodet 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.

Solid PR — the disconnect handling and reconnection logic are well-designed with proper thread safety.

The AtomicBoolean reconnection guard prevents concurrent reconnect attempts, the volatile upgrades on client and taskExecutor combined with local-reference captures (final BayeuxClient disconnectedClient = client) are the correct idiom for safe publication across threads, and the shutdown sequence in doStop() correctly removes the disconnect listener before calling client.disconnect() so that client-initiated disconnects during shutdown won't trigger reconnection.

The test follows existing patterns in SubscriptionHelperManualIT and validates the complete disconnect → reconnect → resubscribe lifecycle, including the await().during(1, SECONDS) assertion that catches any double-reconnection races.

Two minor observations (neither blocking):

  1. In createDisconnectListener(), the catch block only handles RejectedExecutionException. If executor.execute() threw any other unchecked exception, the reconnecting flag would remain true, permanently disabling reconnection. In practice RejectedExecutionException is the only runtime exception ScheduledThreadPoolExecutor.execute() can throw, so this is fine — just noting for completeness.

  2. reconnectAfterDisconnect() calls disconnectedClient.waitFor(waitMs, DISCONNECTED) which blocks the taskExecutor thread for up to 120 seconds. This is an acceptable trade-off given the existing design, but worth noting for future reference.

📋 PR Metadata

Aspect Current Suggested
Labels components + bug
Milestone (none) 4.23.0

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of Guillaume Nodet

gnodet added a commit to gnodet/camel that referenced this pull request Aug 31, 2026
@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • components/camel-salesforce/camel-salesforce-component

🔬 Scalpel shadow comparison — Scalpel: 11 tested, 27 compile-only — current: 11 all tested

Maveniverse Scalpel detected 38 affected modules (current approach: 11).

⚠️ Modules only in Scalpel (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

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

Modules Scalpel would test (11)
  • camel-jbang-mcp
  • camel-jbang-plugin-mcp
  • camel-jbang-plugin-route-parser
  • camel-jbang-plugin-tui
  • camel-jbang-plugin-validate
  • camel-launcher-container
  • camel-salesforce
  • camel-salesforce-codegen
  • camel-salesforce-maven-plugin
  • camel-yaml-dsl-validator
  • camel-yaml-dsl-validator-maven-plugin
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 (38 modules)
  • Camel :: All Components Sync point
  • Camel :: Assembly
  • Camel :: Catalog :: Camel Catalog
  • Camel :: Catalog :: Camel Report Maven Plugin
  • Camel :: Catalog :: Camel Route Parser
  • Camel :: Catalog :: Console
  • Camel :: Catalog :: Dummy Component
  • Camel :: Catalog :: Maven
  • Camel :: Catalog :: Suggest
  • Camel :: Component DSL
  • Camel :: Coverage
  • Camel :: Docs
  • Camel :: Endpoint DSL
  • Camel :: Endpoint DSL :: Support
  • Camel :: Integration Tests
  • Camel :: JBang :: Core
  • Camel :: JBang :: Integration tests
  • Camel :: JBang :: MCP
  • Camel :: JBang :: Main
  • Camel :: JBang :: Plugin :: Edit
  • Camel :: JBang :: Plugin :: Generate
  • Camel :: JBang :: Plugin :: Kubernetes
  • Camel :: JBang :: Plugin :: MCP
  • Camel :: JBang :: Plugin :: Route Parser
  • Camel :: JBang :: Plugin :: TUI
  • Camel :: JBang :: Plugin :: Testing
  • Camel :: JBang :: Plugin :: Validate
  • Camel :: Kamelet Main
  • Camel :: Launcher
  • Camel :: Launcher :: Container
  • Camel :: Salesforce
  • Camel :: Salesforce :: CodeGen
  • Camel :: Salesforce :: Maven Plugin
  • Camel :: YAML DSL
  • Camel :: YAML DSL :: Deserializers
  • Camel :: YAML DSL :: Maven Plugins
  • Camel :: YAML DSL :: Validator
  • Camel :: YAML DSL :: Validator Maven Plugin

⚙️ View full build and test results

…tate in the http worker thread instead of a single-threaded executor service not to block the latter. Also, disconnect timeout has been reduced to 10 seconds

@gnodet gnodet 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.

Well-implemented handling of Salesforce Streaming API 64.0 server-initiated disconnect messages. The core design is solid: the AtomicBoolean guard prevents concurrent reconnects, volatile fields ensure visibility across threads, and isStoppingOrStopped() checks at multiple points properly handle the shutdown race. Capturing the client reference locally as disconnectedClient and comparing against the field later is a nice pattern to detect stop/restart.

A few observations (none blocking):

  1. Formatting noise: The PR mixes ~70% formatting-only changes (re-wrapping lambdas, String.format arguments, method signatures) with the functional additions (disconnect listener, reconnect method, volatile fields). This makes the functional diff harder to isolate and increases merge conflict risk. Consider splitting formatting into a separate commit in future PRs.

  2. Exception handling in createDisconnectListener(): Only RejectedExecutionException is caught. If component.getHttpClient() or getWorkerPool() throws an unexpected NPE or other RuntimeException during partial shutdown, the reconnecting AtomicBoolean stays true, permanently preventing future reconnect attempts. A finally block to reset the flag would add resilience.

  3. Disconnect timeout: When waitFor(DISCONNECT_TIMEOUT_SEC, DISCONNECTED) times out, the method logs a warning and returns without scheduling a retry — the subscription is silently lost. Consider making the timeout configurable or scheduling a delayed retry.

  4. Reconnect backoff: disconnectedClient.handshake() is called without delay. If the server immediately disconnects again (misconfigured/failing server), this could produce a tight reconnect loop. A brief delay before the first reconnect after a server disconnect would add resilience.

The test follows the established StubServer pattern and the disconnect message accurately reflects what Salesforce sends. The volatile additions to client and taskExecutor are appropriate corrections for pre-existing visibility gaps.

📋 PR Metadata

Aspect Current Suggested
Milestone (none) 4.23.0

LGTM ✅

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of Guillaume Nodet

@davsclaus
davsclaus merged commit 9e62fa3 into apache:main Aug 31, 2026
5 checks passed
@davsclaus davsclaus added the enhancement New feature or request label Aug 31, 2026
@davsclaus davsclaus added this to the 4.23.0 milestone Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

components enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants