[improve][admin] PIP-482: Peek messages from topic subscription with messagePosition#25911
Open
Pruthvirajj240 wants to merge 1 commit into
Open
[improve][admin] PIP-482: Peek messages from topic subscription with messagePosition#25911Pruthvirajj240 wants to merge 1 commit into
Pruthvirajj240 wants to merge 1 commit into
Conversation
…messagePosition
Adds a messagePosition parameter to the Topics.peekMessages admin client API,
enabling efficient pagination through a subscription backlog without
fetching all preceding messages. The underlying REST endpoint
(/admin/v3/persistent/{...}/subscription/{...}/position/{N}) has always
supported this; the Java admin client previously hardcoded position=1.
API design:
- The 6-arg method peekMessages(topic, sub, messagePosition, numMessages,
showServerMarker, transactionIsolationLevel) is the primary abstract.
- All pre-existing peek overloads become default methods that delegate
to it, eliminating duplicated Javadoc across overloads.
- Parameter is named messagePosition (matching the REST endpoint and the
internal nthMessage field) instead of offset (Kafka terminology).
Files changed:
- pip/pip-482.md: PIP markdown with motivation, API surface, alternatives
considered (MessageId-based, PeekOptions builder), and binary-
compatibility analysis.
- pulsar-client-admin-api/.../Topics.java: new abstract method plus four
default-method overloads (3/4/5-arg sync and 3/4/5-arg async) so all
existing call sites remain source- and behavior-compatible.
- pulsar-client-admin/.../internal/TopicsImpl.java: implements the new
abstract method; adds checkArgument(messagePosition >= 1).
- pulsar-client-admin/.../TopicsInterfaceDefaultsTest.java: unit tests
for all six delegation paths using Mockito CALLS_REAL_METHODS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Adds a
messagePositionparameter to the Java admin clientTopics.peekMessages/peekMessagesAsyncAPI, enabling efficient pagination through a subscription backlog withoutfetching all preceding messages.
The underlying REST endpoint
/admin/v3/persistent/{tenant}/{namespace}/{topic}/subscription/{subName}/position/{N}already accepts an arbitrary message position. The Java admin client has historically
hardcoded
1, so callers could only inspect the head of the backlog. The most common usecase affected by this gap is UI pagination — to display the 91st–100th messages on a backlog
page, a caller has to fetch and discard the first 90.
PIP-482 surfaces the existing server capability at the Java client level.
Modifications
pip/pip-482.md(new) — formal proposal document with motivation, full API surface,alternatives considered (
MessageId-based,PeekOptionsbuilder), and binary-compatibilityanalysis.
pulsar-client-admin-api/.../Topics.java— adds the primary abstract methodpeekMessages(topic, subName, messagePosition, numMessages, showServerMarker, isolation)and its async variant. All pre-existing peek overloads become
defaultmethods thatdelegate to it, giving the interface a single source of Javadoc.
pulsar-client-admin/.../internal/TopicsImpl.java— implements the new primary abstractmethod. The internal recursive helper already took the position as
nthMessage— the changeis to pass the caller-supplied
messagePositioninstead of hardcoded1. AddscheckArgument(messagePosition >= 1)for client-side validation.pulsar-client-admin/.../TopicsInterfaceDefaultsTest.java(new) — unit tests coveringdelegation of all six
peekMessages/peekMessagesAsyncoverloads to the primary abstractmethod, with expected
messagePositionand parameter forwarding asserted via MockitoCALLS_REAL_METHODS.Verifying this change
./gradlew :pulsar-client-admin-api:compileJava :pulsar-client-admin-original:compileJava :pulsar-client-admin-original:compileTestJava./gradlew :pulsar-client-admin-original:test --tests "org.apache.pulsar.client.admin.TopicsInterfaceDefaultsTest"→ 6 tests, 0 failures, 0 errors
messagePosition=91, numMessages=10, verify the returned messages match positions 91–100.(Reviewer note: I will add a broker integration test in a follow-up if requested. The
change is fundamentally a client-side surface change — the REST endpoint already supports
arbitrary positions and is exercised by existing broker tests.)
Note on test location: The new unit test lives in
pulsar-client-admin/src/test/(notpulsar-client-admin-api/src/test/) because the latter has no existing test infrastructureconfigured. The test still covers the
Topicsinterface defaults (from the api module) — itruns in the admin module's test classpath where Mockito and TestNG are wired up via the
convention plugin (
pulsar.public-java-library-conventions).Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes:
The change extends the public Java admin client API with one new abstract method per sync/async
variant and four new default-method overloads. All pre-existing call sites remain source- and
behavior-compatible. See PIP-482 "Backward & Forward Compatibility" for full analysis.
Documentation
doc-requiredDocumentation update will follow as a separate PR to
apache/pulsar-siteonce this lands.doc-not-neededdocdoc-completeMatching PR in forked repository
PR in forked repository: to be filled after the fork branch is pushed