Produce
Description: Send a single message to the topic. Method:POST
Path: /admin/rest/topics/v1/<domain>/<tenant>/<namespace>/<topic>/message
Request headers(*
means required):
Accept:application/json *
Accept the response body in JSON formatContent-Type: application/octet-stream *
Send the request body in binary formatX-Pulsar-Long-Schema-Version
Schema version in long typeX-Pulsar-Sequence-Id
Message sequence IDX-Pulsar-Event-Time
Message event timeX-Pulsar-Property-<key>
Message property, key-value pairX-Pulsar-Partition-Key
Message key
Binary data
Response headers:
Content-Type: application/json *
Send the response body in JSON format
String
: message ID in string format
Status code:
201
: Send single message success400
: Wrong request params401
: Unauthorized404
: Topic/Schema doesn’t exist500
: Internal server error
JsonObject
:
reason(string
): error information
Consume
Description: Consume a single message from the topic. Method:POST
Path: /admin/rest/topics/v1/<domain>/<tenant>/<namespace>/<topic>/<subscriptionName>/message
Request headers(*
means required):
Accept:application/octet-stream *
Accept the response body in JSON formatContent-Type: application/json *
Send the request body in binary format
JsonObject
:timeoutMillis (int)
: 3000
*
means required):
Content-Type: application/octet-stream *
Send the response body in JSON formatX-Pulsar-Base64-Schema-Version
Schema version in base64 encoded formatX-Pulsar-Long-Schema-Version
Schema version in long typeX-Pulsar-Message-Id *
Message ID in base64 encoded formatX-Pulsar-Message-String-Id *
Message ID in string formatX-Pulsar-Sequence-Id
Message sequence IDX-Pulsar-Event-Time
Message event timeX-Pulsar-Property-<key>
Message property, key-value pairX-Pulsar-Partition-Key
Message key
Binary data
Status code:
200
: Get single message success204
: Get null message by timeout400
: Wrong request params401
: Unauthorized404
: Topic doesn’t exist500
: Internal server error
JsonObject
:- reason(
string
): error information
- reason(
Acknowledge
Description: Acknowledge a single message from the topic. Method:PUT
Path: /admin/rest/topics/v1/<domain>/<tenant>/<namespace>/<topic>/<subscriptionName>/message
Request headers(*
means required):
Accept: application/json *
Accept the response body in JSON formatContent-Type: application/json *
Send the request body in binary format
String
: message ID in base64 encoded format, it can be obtained from the response header x-pulsar-message-id
of the API consume.
Response body:
no content
Status code:
204
: Acknowledge success400
: Wrong request params401
: Unauthorized404
: Topic doesn’t exist500
: Internal server error
JsonObject
:
reason(string
): error information
Working with Schemas
pulsar-rest supports all schemas and is compatible with the Pulsar client in other languages. If you want to produce/consume a topic with schemas through pulsar-rest, see the following example. Pulsar schema uses the Pulsar Admin API to create. see manage schemas to learn the schema API or see create schema for topics to learn topic schema management on the StreamNative Console.Binary Data
Because the HTTP client needs to send binary data, use the cURL tool to encode the stringHi Pulsar
into UTF-8 format bytes. If you need to send bytes in another format, specify the appropriate file. For more information see the cURL documentation.
Avro Base Struct Schema
Pulsar uses Avro Specification to declare the schema definition forAvroBaseStructSchema
, which supports AvroSchema
, JsonSchema
, and ProtobufSchema
.
Multi-version schema
For basic schema types like String and JSON, pulsar-rest will automatically take the schema of the topic and put it into the metadata of the message. The client in other languages will serialize/deserialize the data based on this metadata.String Schema
Create topic schemaJSON Schema
Create topic schemaAvro Schema
Create topic schema~/test-avro-student.avsc
~/test-avro-student.json
If you dont have
avro-tools
installed, see the Avro product page.X-Pulsar-Long-Schema-Version
Schema version in long type
Protobuf Schema
Create topic schema~/test-proto-test.proto
~/test-proto-message.txt
X-Pulsar-Long-Schema-Version
Schema version in long type