Skip to content

Commit 756426b

Browse files
author
zhangzhibiao
committed
add operation timeout ms interface
1 parent 070132b commit 756426b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

include/pulsar/ClientConfiguration.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,19 @@ class PULSAR_PUBLIC ClientConfiguration {
9292
*/
9393
int getOperationTimeoutSeconds() const;
9494

95+
/**
96+
* Set timeout on client operations (subscribe, create producer, close, unsubscribe) in milliseconds.
97+
* Overrides the value set by setOperationTimeoutSeconds if called after it.
98+
*
99+
* @param timeoutMs the timeout in milliseconds after which the operation will be considered as failed
100+
*/
101+
ClientConfiguration& setOperationTimeoutMs(int timeoutMs);
102+
103+
/**
104+
* @return the client operations timeout in milliseconds
105+
*/
106+
int getOperationTimeoutMs() const;
107+
95108
/**
96109
* Set the number of IO threads to be used by the Pulsar client. Default is 1
97110
* thread.

lib/ClientConfiguration.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ int ClientConfiguration::getOperationTimeoutSeconds() const {
7070
return std::chrono::duration_cast<std::chrono::seconds>(impl_->operationTimeout).count();
7171
}
7272

73+
ClientConfiguration& ClientConfiguration::setOperationTimeoutMs(int timeoutMs) {
74+
impl_->operationTimeout = std::chrono::milliseconds(timeoutMs);
75+
return *this;
76+
}
77+
78+
int ClientConfiguration::getOperationTimeoutMs() const {
79+
return static_cast<int>(
80+
std::chrono::duration_cast<std::chrono::milliseconds>(impl_->operationTimeout).count());
81+
}
82+
7383
ClientConfiguration& ClientConfiguration::setIOThreads(int threads) {
7484
impl_->ioThreads = threads;
7585
return *this;

0 commit comments

Comments
 (0)