Schemas, like other entities in Pulsar, can be managed using the admin API.
A Pulsar schema is a fairly simple data structure stored in Pulsar for representing the structure of messages stored in a Pulsar topic. The schema structure consists of:
dev
or prod
, etc.All the schemas are versioned with versions. So you can retrieve the schema definition of a given version if the version is not deleted.
You can upload a new schema using the upload
subcommand:
$ pulsar-admin schemas upload <topic-name> --filename /path/to/schema-definition-file
The schema definition file should contain following json string on defining how the schema look like:
{ "type": "STRING", "schema": "", "properties": { "key1" : "value1" } }
An example of the schema definition file can be found at {@inject: github:SchemaExample:/conf/schema_example.conf}.
{@inject: endpoint|POST|/admin/v2/schemas/:tenant/:namespace/:topic/schema|operation/uploadSchema?version=[[pulsar:version_number]]}
You can get the latest version of Schema using the get
subcommand.
$ pulsar-admin schemas get <topic-name> { "version": 0, "type": "String", "timestamp": 0, "data": "string", "properties": { "property1": "string", "property2": "string" } }
You can also retrieve the Schema of a given version by specifying --version
option.
$ pulsar-admin schemas get <topic-name> --version <version>
Retrieve the latest version of the schema:
{@inject: endpoint|GET|/admin/v2/schemas/:tenant/:namespace/:topic/schema|operation/getSchema?version=[[pulsar:version_number]]}
Retrieve the schema of a given version:
{@inject: endpoint|GET|/admin/v2/schemas/:tenant/:namespace/:topic/schema/:version|operation/getSchema?version=[[pulsar:version_number]]}
You can delete a schema using the delete
subcommand.
$ pulsar-admin schemas delete <topic-name>
{@inject: endpoint|DELETE|/admin/v2/schemas/:tenant/:namespace/:topic/schema|operation/deleteSchema?version=[[pulsar:version_number]]}