apache / apache/pulsar

[Enhancement] Set default value to MessageId.Latest in subscription creating API

Open
#23,661 9 comments 0 reactions 1 assignee Claimed by @poorbarcode View on GitHub
type/enhancement
Dominant language
Java
Stars
15.3k
Forks
3.8k
Avg merge
1d 14h
Merged PRs (30d)
160

Description

### Search before asking

- [X] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.

### Motivation

We met a corner case when invoking subscription creating API. If client sends a empty JSON object, the backend service will create a subscription with earliest initialPosition.
Likes this, the requestBody JSON object, is deserialized to API param `ResetCursorData.java` instance, `ledgerId` and `entryId` are set to `0`.
image
```java
public class ResetCursorData {
protected long ledgerId;
protected long entryId;
protected int partitionIndex = -1;
protected boolean isExcluded = false;
protected int batchIndex = -1;
protected Map properties;

}
```
In Pulsar, if client didn't set a specific value, the expected is Latest. But in the situation above, subscription was created with earliest position.

### Solution

In the creating subscription API, the requestBody param ResetCursorData.java, set `ledgerId` and `entryId` to `Long.MAX_VALUE`, not `long` default value `0`.

### Alternatives

_No response_

### Anything else?

_No response_

### Are you willing to submit a PR?

- [X] I'm willing to submit a PR!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.