peek message for pulsar-admin java client does not return a key of a peeked message
- Dominant language
- Java
- Stars
- 15.3k
- Forks
- 3.8k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 160
Description
**Describe the bug**
For messages got via pulsarAdmin.topics().peekMessages(topic, subscription, total) method from pulsar-client-admin, getKey() method always returns an empty string.
**To Reproduce**
Steps to reproduce the behavior:
1. Write some messages with specified message keys to a topic
2. Call pulsarAdmin.topics().peekMessages(topic, subscription, total); (pulsarAdmin is an instance of org.apache.pulsar.client.admin.PulsarAdmin)
3. For a message from a list of message received on previous step call getKey() method
4. empty string will be returned
**Expected behavior**
getKey() method should return a message key.
**Screenshots**
E.g. of getKey() result for a peeked message:

E.g. of getKey() result for the same message which was received (with pulsar-client v2.7.2):

**Desktop (please complete the following information):**
we are using pulsar-client-admin v2.7.2
```
org.apache.pulsar
pulsar-client-admin
2.7.2
```
**Additional context**
A bit of a shot in the dark, but I think this happens because for peeked message getKey() returns a partiton key from metadata, but not the actual key itself.
See org.apache.pulsar.client.impl.MessageImpl:

AFAIK pulsar-admin java client uses pulsar-admin rest api, and API doesn't actually return a key, only metadata.getPartitionKey().
See https://github.com/apache/pulsar/blob/a2b7cae3cfe8d3776483b1ecaf69af47949b70e1/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java#L2595
Though I can be completely wrong here
Contributor guide
Research direction
Start with pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java around line 2595 and inspect how peekMessages data is exposed through the REST API. Compare that response with org.apache.pulsar.client.impl.MessageImpl and the pulsarAdmin.topics().peekMessages entry point. Done means a peeked message's getKey() returns the original message key.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, distributed-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100