Github issue: https://github.com/apache/pulsar/issues/17947.

Motivation

Currently, pulsar-admin topics peek-messages and the REST equivalent return
the message payload in their original binary form. In the case that the
topic has a complex schema, for example, AVRO, protobuf-encoded binary is
returned. This results in two issues.

   1. The output can be unreadable with hidden charractors.
   2. The response from the REST API doesn't conform to HTTP standard.
   Binary data are not properly encoded or have the right headers set.

Goal

Ability to ask Pulsar broker's Admin API to return properly encoded string
payload, instead of binary payload.
API Changes

   1. API
   
/admin/v2/:schema/:tenant/:namespace/:topic/subscription/:subName/position/:messagePosition
   
<https://pulsar.apache.org/admin-rest-api?version=2.10.1&apiversion=v2#operation/peekNthMessage>
will
   have an optional query parameter asString. Valid values are true or false.
   When set to be true, the returned payload will be encoded according to
   the topic's schema.
   2. pulsar-admin topics peek-messages will add an optional flag --string.
   If set to true, output would have the payload encoded as string per the
   topic's schema.

Implementation

When handling peek request, broker admin currently first retrieves the
entry from managed ledger. Then read the binary form from the entry before
packaging it as part of REST response.

Before the binary is returned, the broker would make a request to
schemaRegistryService asking for the schema from the schema storage. Once
found, the broker would read the schema and encode the payload accordingly.

-- 

Lin Zhao

Director of Engineering

e: lin.z...@streamnative.io <lin.z...@streamnative.io>

streamnative.io

Reply via email to