Skip to content

Add auto cluster failover support#487

Open
shibd wants to merge 2 commits into
apache:masterfrom
shibd:codex/auto-cluster-failover
Open

Add auto cluster failover support#487
shibd wants to merge 2 commits into
apache:masterfrom
shibd:codex/auto-cluster-failover

Conversation

@shibd
Copy link
Copy Markdown
Member

@shibd shibd commented Jun 2, 2026

Motivation

The Node.js client did not expose the cluster-level failover support added in the C++ client, so applications could not automatically switch from a primary Pulsar cluster to a secondary cluster when the primary became unavailable.

Changes

  • Add serviceUrlProvider support to ClientConfig and wire it to the C++ pulsar::AutoClusterFailover implementation.
  • Support primary and secondary service info entries with optional per-cluster authentication and TLS trust cert configuration.
  • Preserve the existing serviceUrl client path and validate that serviceUrl and serviceUrlProvider are not configured together.
  • Keep authentication bindings alive for top-level and per-cluster authentication objects.
  • Add a dedicated failoverClientTest integration test that starts two standalone Pulsar clusters, stops the primary, and verifies the same client can continue producing and consuming through the secondary.

Validation

  • npm run type-check
  • ./node_modules/.bin/node-pre-gyp build
  • npx jest tests/failoverClientTest.test.js --runInBand

Related to #479.

@shibd shibd self-assigned this Jun 2, 2026
@shibd shibd added this to the 1.18.0 milestone Jun 2, 2026
@shibd shibd marked this pull request as ready for review June 2, 2026 11:31
@shibd shibd requested a review from Copilot June 2, 2026 11:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR exposes Pulsar C++ AutoClusterFailover functionality through the Node.js client by adding a serviceUrlProvider option to ClientConfig, enabling automatic failover from a primary cluster to one or more secondary clusters. It also introduces a new integration test that spins up two standalone Pulsar clusters and validates continued produce/consume after the primary is stopped.

Changes:

  • Add serviceUrlProvider parsing/validation in the native addon and construct a client using pulsar::AutoClusterFailover when configured.
  • Allow per-cluster ServiceInfo entries (service URL + optional per-cluster auth and TLS trust certs), while keeping auth bindings alive.
  • Add an integration test that starts two clusters, stops the primary, and verifies the client continues working via the secondary.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/failoverClientTest.test.js New integration test that runs two standalone clusters and verifies automatic failover behavior.
tests/client.test.js Updates the “missing serviceUrl” error expectation to account for serviceUrlProvider.
src/Client.h Replaces single auth reference with a vector to keep multiple auth bindings alive (top-level + per-cluster).
src/Client.cc Implements serviceUrlProvider wiring to C++ AutoClusterFailover, plus config validation and ServiceInfo/auth handling.
index.d.ts Updates TS typings to enforce mutual exclusivity between serviceUrl and serviceUrlProvider, and adds ServiceInfo/AutoClusterFailoverConfig types.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Client.cc Outdated
Comment on lines 319 to 326
if (!hasServiceUrlProvider && (!hasServiceUrl || !clientConfig.Get(CFG_SERVICE_URL).IsString() ||
clientConfig.Get(CFG_SERVICE_URL).ToString().Utf8Value().empty())) {
Napi::Error::New(env,
"Service URL is required and must be specified as a string unless serviceUrlProvider "
"is configured")
.ThrowAsJavaScriptException();
return;
}
Comment thread src/Client.cc Outdated
Comment thread src/Client.cc Outdated
Comment thread src/Client.cc
Comment thread tests/failoverClientTest.test.js Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants