Skip to content

Commit f25b90d

Browse files
authored
Support set connectionTimeout param (#410)
1 parent d4251d4 commit f25b90d

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export interface ClientConfig {
3333
listenerName?: string;
3434
log?: (level: LogLevel, file: string, line: number, message: string) => void;
3535
logLevel?: LogLevel;
36+
connectionTimeoutMs?: number;
3637
}
3738

3839
export class Client {

src/Client.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <pulsar/c/client.h>
2727
#include <pulsar/c/client_configuration.h>
2828
#include <pulsar/c/result.h>
29+
#include "pulsar/ClientConfiguration.h"
2930

3031
static const std::string CFG_SERVICE_URL = "serviceUrl";
3132
static const std::string CFG_AUTH = "authentication";
@@ -42,9 +43,14 @@ static const std::string CFG_STATS_INTERVAL = "statsIntervalInSeconds";
4243
static const std::string CFG_LOG = "log";
4344
static const std::string CFG_LOG_LEVEL = "logLevel";
4445
static const std::string CFG_LISTENER_NAME = "listenerName";
46+
static const std::string CFG_CONNECTION_TIMEOUT = "connectionTimeoutMs";
4547

4648
LogCallback *Client::logCallback = nullptr;
4749

50+
struct _pulsar_client_configuration {
51+
pulsar::ClientConfiguration conf;
52+
};
53+
4854
void Client::SetLogHandler(const Napi::CallbackInfo &info) {
4955
Napi::Env env = info.Env();
5056
Napi::HandleScope scope(env);
@@ -157,6 +163,13 @@ Client::Client(const Napi::CallbackInfo &info) : Napi::ObjectWrap<Client>(info)
157163
}
158164
}
159165

166+
if (clientConfig.Has(CFG_CONNECTION_TIMEOUT) && clientConfig.Get(CFG_CONNECTION_TIMEOUT).IsNumber()) {
167+
int32_t connectionTimeoutMs = clientConfig.Get(CFG_CONNECTION_TIMEOUT).ToNumber().Int32Value();
168+
if (connectionTimeoutMs > 0) {
169+
cClientConfig.get()->conf.setConnectionTimeout(connectionTimeoutMs);
170+
}
171+
}
172+
160173
if (clientConfig.Has(CFG_LISTENER_THREADS) && clientConfig.Get(CFG_LISTENER_THREADS).IsNumber()) {
161174
int32_t messageListenerThreads = clientConfig.Get(CFG_LISTENER_THREADS).ToNumber().Int32Value();
162175
if (messageListenerThreads > 0) {

tests/end_to_end.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const Pulsar = require('../index');
3232
serviceUrl,
3333
tlsTrustCertsFilePath: `${__dirname}/certificate/server.crt`,
3434
operationTimeoutSeconds: 30,
35+
connectionTimeoutMs: 20000,
3536
listenerName,
3637
});
3738

0 commit comments

Comments
 (0)