Add auto cluster failover support#487
Open
shibd wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
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
serviceUrlProviderparsing/validation in the native addon and construct a client usingpulsar::AutoClusterFailoverwhen configured. - Allow per-cluster
ServiceInfoentries (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 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
serviceUrlProvidersupport toClientConfigand wire it to the C++pulsar::AutoClusterFailoverimplementation.serviceUrlclient path and validate thatserviceUrlandserviceUrlProviderare not configured together.failoverClientTestintegration 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 buildnpx jest tests/failoverClientTest.test.js --runInBandRelated to #479.