Skip to content

Support set connectionTimeout param #410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface ClientConfig {
listenerName?: string;
log?: (level: LogLevel, file: string, line: number, message: string) => void;
logLevel?: LogLevel;
connectionTimeoutMs?: number;
}

export class Client {
Expand Down
13 changes: 13 additions & 0 deletions src/Client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <pulsar/c/client.h>
#include <pulsar/c/client_configuration.h>
#include <pulsar/c/result.h>
#include "pulsar/ClientConfiguration.h"

static const std::string CFG_SERVICE_URL = "serviceUrl";
static const std::string CFG_AUTH = "authentication";
Expand All @@ -42,9 +43,14 @@ static const std::string CFG_STATS_INTERVAL = "statsIntervalInSeconds";
static const std::string CFG_LOG = "log";
static const std::string CFG_LOG_LEVEL = "logLevel";
static const std::string CFG_LISTENER_NAME = "listenerName";
static const std::string CFG_CONNECTION_TIMEOUT = "connectionTimeoutMs";

LogCallback *Client::logCallback = nullptr;

struct _pulsar_client_configuration {
pulsar::ClientConfiguration conf;
};

void Client::SetLogHandler(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Expand Down Expand Up @@ -157,6 +163,13 @@ Client::Client(const Napi::CallbackInfo &info) : Napi::ObjectWrap<Client>(info)
}
}

if (clientConfig.Has(CFG_CONNECTION_TIMEOUT) && clientConfig.Get(CFG_CONNECTION_TIMEOUT).IsNumber()) {
int32_t connectionTimeoutMs = clientConfig.Get(CFG_CONNECTION_TIMEOUT).ToNumber().Int32Value();
if (connectionTimeoutMs > 0) {
cClientConfig.get()->conf.setConnectionTimeout(connectionTimeoutMs);
}
}

if (clientConfig.Has(CFG_LISTENER_THREADS) && clientConfig.Get(CFG_LISTENER_THREADS).IsNumber()) {
int32_t messageListenerThreads = clientConfig.Get(CFG_LISTENER_THREADS).ToNumber().Int32Value();
if (messageListenerThreads > 0) {
Expand Down
1 change: 1 addition & 0 deletions tests/end_to_end.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
serviceUrl,
tlsTrustCertsFilePath: `${__dirname}/certificate/server.crt`,
operationTimeoutSeconds: 30,
connectionTimeoutMs: 20000,
listenerName,
});

Expand Down Expand Up @@ -310,7 +311,7 @@
});

let consumer2Recv = 0;
while (true) {

Check warning on line 314 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

Unexpected constant condition

Check warning on line 314 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

Unexpected constant condition
try {
const msg = await consumer2.receive(3000);
await new Promise((resolve) => setTimeout(resolve, 10));
Expand Down Expand Up @@ -355,7 +356,7 @@
topic,
startMessageId: Pulsar.MessageId.earliest(),
receiverQueueSize: 10,
listener: async (message, reader) => {

Check warning on line 359 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

'message' is defined but never used

Check warning on line 359 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

'reader' is defined but never used

Check warning on line 359 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

'message' is defined but never used
await new Promise((resolve) => setTimeout(resolve, 10));
reader1Recv += 1;
},
Expand Down Expand Up @@ -387,7 +388,7 @@
await client.close();
});

test('Message Listener error handling', async () => {

Check warning on line 391 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

Test has no assertions
const client = new Pulsar.Client({
serviceUrl: 'pulsar://localhost:6650',
});
Expand Down Expand Up @@ -423,7 +424,7 @@
subscription: 'sync',
subscriptionType: 'Shared',
subscriptionInitialPosition: 'Earliest',
listener: (message, messageConsumer) => {

Check warning on line 427 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

'message' is defined but never used

Check warning on line 427 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

'messageConsumer' is defined but never used
throw new Error('consumer1 callback expected error');
},
});
Expand All @@ -433,7 +434,7 @@
subscription: 'async',
subscriptionType: 'Shared',
subscriptionInitialPosition: 'Earliest',
listener: async (message, messageConsumer) => {

Check warning on line 437 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

'message' is defined but never used

Check warning on line 437 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

'messageConsumer' is defined but never used
throw new Error('consumer2 callback expected error');
},
});
Expand Down
Loading