apache / pulsar

Apache Pulsar - distributed pub-sub messaging system
https://pulsar.apache.org/
Apache License 2.0
14.23k stars 3.58k forks source link

[Bug] Peek nth message REST API returns incorrect data #23228

Closed gaecfov closed 2 months ago

gaecfov commented 2 months ago

Search before asking

Read release policy

Version

Pulsar Version:3.3.0 REST API:/persistent/{tenant}/{namespace}/{topic}/subscription/{subName}/position/{messagePosition}

Minimal reproduce step

curl --location --request GET '/admin/v2/persistent/public/default/my-topic/subscription/my-sub/position/1‘

What did you expect to see?

Because the messagePosition parameter is set to 1, a message should normally be returned

What did you see instead?

Multiple messages are returned. It looks like one Batch message. How do I parse this message? I need to display this message on the page

image

Anything else?

No response

Are you willing to submit a PR?

dao-jun commented 2 months ago

The rest API returns binary data response, not JSON. To decode the message, you have to use Pulsar Client API.

crossoverJie commented 2 months ago

https://github.com/apache/pulsar/blob/679a3d49eefc2a82bbeba085c258b1f2b751f28a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java#L710

https://github.com/apache/pulsar/blob/20e83b96c3fcf10010977ab785093e105e4e40d8/pulsar-client-admin-api/src/main/java/org/apache/pulsar/client/admin/Topics.java#L1657

Use admin client instead of rest api.

gaecfov commented 2 months ago

The GUI tool I am developing uses the rest api directly, without the admin client, and I currently do message extraction based on raw data