This is an automated email from the ASF dual-hosted git repository.
xyz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pulsar-client-cpp.git
The following commit(s) were added to refs/heads/main by this push:
new bda51d6 [feat][client-cpp] Add operation timeout configuration in
milliseconds (#543)
bda51d6 is described below
commit bda51d6ecf8eaeb79aecac9ae2ce3802866cea32
Author: zhanglistar <[email protected]>
AuthorDate: Wed Mar 4 15:40:09 2026 +0800
[feat][client-cpp] Add operation timeout configuration in milliseconds
(#543)
---
include/pulsar/ClientConfiguration.h | 13 +++++++++++++
lib/CMakeLists.txt | 1 +
lib/ClientConfiguration.cc | 10 ++++++++++
3 files changed, 24 insertions(+)
diff --git a/include/pulsar/ClientConfiguration.h
b/include/pulsar/ClientConfiguration.h
index 03e56e7..98ccff7 100644
--- a/include/pulsar/ClientConfiguration.h
+++ b/include/pulsar/ClientConfiguration.h
@@ -92,6 +92,19 @@ class PULSAR_PUBLIC ClientConfiguration {
*/
int getOperationTimeoutSeconds() const;
+ /**
+ * Set timeout on client operations (subscribe, create producer, close,
unsubscribe) in milliseconds.
+ * Overrides the value set by setOperationTimeoutSeconds if called after
it.
+ *
+ * @param timeoutMs the timeout in milliseconds after which the operation
will be considered as failed
+ */
+ ClientConfiguration& setOperationTimeoutMs(int timeoutMs);
+
+ /**
+ * @return the client operations timeout in milliseconds
+ */
+ int getOperationTimeoutMs() const;
+
/**
* Set the number of IO threads to be used by the Pulsar client. Default
is 1
* thread.
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index b877560..3478f10 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -41,6 +41,7 @@ else ()
set(PULSAR_SOURCES ${PULSAR_SOURCES} ${PROTO_SOURCES})
ADD_CUSTOM_COMMAND(
OUTPUT ${PROTO_SOURCES}
+ COMMAND ${CMAKE_COMMAND} -E echo "Generating PulsarApi.pb.cc/h
with: ${PROTOC_PATH} -I ../proto ../proto/PulsarApi.proto
--cpp_out=${LIB_AUTOGEN_DIR}"
COMMAND ${PROTOC_PATH} -I ../proto ../proto/PulsarApi.proto
--cpp_out=${LIB_AUTOGEN_DIR}
DEPENDS
../proto/PulsarApi.proto
diff --git a/lib/ClientConfiguration.cc b/lib/ClientConfiguration.cc
index 05de194..b99c5d2 100644
--- a/lib/ClientConfiguration.cc
+++ b/lib/ClientConfiguration.cc
@@ -70,6 +70,16 @@ int ClientConfiguration::getOperationTimeoutSeconds() const {
return
std::chrono::duration_cast<std::chrono::seconds>(impl_->operationTimeout).count();
}
+ClientConfiguration& ClientConfiguration::setOperationTimeoutMs(int timeoutMs)
{
+ impl_->operationTimeout = std::chrono::milliseconds(timeoutMs);
+ return *this;
+}
+
+int ClientConfiguration::getOperationTimeoutMs() const {
+ return static_cast<int>(
+
std::chrono::duration_cast<std::chrono::milliseconds>(impl_->operationTimeout).count());
+}
+
ClientConfiguration& ClientConfiguration::setIOThreads(int threads) {
impl_->ioThreads = threads;
return *this;