Skip to content

[feat][client-cpp] Add operation timeout configuration in milliseconds#543

Merged
BewareMyPower merged 2 commits intoapache:mainfrom
bigo-sg:feature/operation-timeout-ms
Mar 4, 2026
Merged

[feat][client-cpp] Add operation timeout configuration in milliseconds#543
BewareMyPower merged 2 commits intoapache:mainfrom
bigo-sg:feature/operation-timeout-ms

Conversation

@zhanglistar
Copy link
Contributor

Fixes #

Master Issue: #

Motivation

ClientConfiguration only exposes operation timeout in seconds via setOperationTimeoutSeconds() / getOperationTimeoutSeconds(). Applications that need sub-second or precise millisecond timeouts (e.g. 500ms, 1500ms) have to convert manually and cannot express values that are not whole seconds. Adding a millisecond-based API allows finer control and avoids conversion in user code.

Modifications

  • include/pulsar/ClientConfiguration.h

    • Added setOperationTimeoutMs(int timeoutMs) to set client operation timeout in milliseconds (subscribe, create producer, close, unsubscribe, etc.).
    • Added getOperationTimeoutMs() const to return the current operation timeout in milliseconds.
    • Documented that calling setOperationTimeoutMs after setOperationTimeoutSeconds overrides the previous value (same internal operationTimeout storage).
  • lib/ClientConfiguration.cc

    • Implemented setOperationTimeoutMs() by assigning std::chrono::milliseconds(timeoutMs) to the existing impl_->operationTimeout (stored as std::chrono::nanoseconds).
    • Implemented getOperationTimeoutMs() by casting operationTimeout to milliseconds and returning the count.

No new fields; all existing code that reads operationTimeout (e.g. ClientImpl::getOperationTimeout, HandlerBase, lookup services) continues to work without change. Backward compatibility is preserved.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage.

(Optional: existing tests that use setOperationTimeoutSeconds (e.g. in ClientTest.cc, ConsumerTest.cc, BasicEndToEndTest.cc) continue to pass; the new ms API uses the same internal value.)

Documentation

  • doc-required (Your PR needs to update docs and you will update later)

  • doc-not-needed
    (New API is self-documenting via existing header comments; no separate doc site change required for a single overload-style API.)

  • doc (Your PR contains doc changes)

  • doc-complete (Docs have been already added)

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}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it helps to debug which protoc used for debug.

@zhanglistar zhanglistar force-pushed the feature/operation-timeout-ms branch from 260a57e to dce1b98 Compare March 4, 2026 02:29
@BewareMyPower BewareMyPower merged commit bda51d6 into apache:main Mar 4, 2026
25 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants