apache / apache/pulsar

peek message for pulsar-admin java client does not return a key of a peeked message

Open
#12,733 6 comments 0 reactions 0 assignees View on GitHub
lifecycle/stale type/bug
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:
![image](https://user-images.githubusercontent.com/2508992/141163650-4758e278-e441-413c-b114-adc7e3b51243.png)

E.g. of getKey() result for the same message which was received (with pulsar-client v2.7.2):
![image](https://user-images.githubusercontent.com/2508992/141163809-4335e64c-f1d3-4b24-820a-b080c19501aa.png)

**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:
![image](https://user-images.githubusercontent.com/2508992/141164735-466284f8-f3ae-4c0a-85d3-0aadf6ea8ed6.png)

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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.