Skip to main content
Construct a schema in your client and pass it when you build a producer or consumer. The client handles serialization on the way out and deserialization on the way in, and the broker registers or validates the schema as described in How it works.

Prerequisites

  • A Pulsar cluster on StreamNative Cloud, and a client configured to connect to it. See Connect to your cluster.
  • A service account with produce and consume permissions on the target topic.

Primitive schemas

bytes

string

The other primitive types follow the same pattern. See Primitive types for the full list and the language-specific type each one maps to.

Key/value schemas

A key/value schema pairs a schema for the key with a schema for the value.
  1. Construct the schema, choosing an encoding type. INLINE puts both key and value in the message payload; SEPARATED stores the key as the message key and the value as the payload.
  2. Produce with it:
  3. Consume with it:

Struct schemas

Avro

Pass a class and Pulsar extracts the schema definition from it.
In C++, Go, and Python, pass the Avro schema definition as a JSON string instead:

JSON

Declaring a JSON schema works the same way as Avro—use Schema.JSON instead of AvroSchema:

Protobuf

  1. Generate the message class with Protobuf 3 or later:
  2. Build a producer and consumer with Schema.PROTOBUF:

ProtobufNative

ProtobufNative uses the Protobuf native descriptor rather than converting to Avro. Construct it exactly as above, substituting Schema.PROTOBUF_NATIVE for Schema.PROTOBUF. Use it when you want native protobuf-v3 serialization or AUTO_CONSUME support.

Native Avro

NATIVE_AVRO wraps an existing org.apache.avro.Schema and accepts an already-serialized Avro payload without re-validating it—useful when you’re ingesting data that another system already validated.

Auto schemas

AUTO_PRODUCE

Use AUTO_PRODUCE_BYTES when your application forwards already-serialized bytes into a topic that has a schema, and you want Pulsar to verify those bytes are compatible before they land.

AUTO_CONSUME

Use AUTO_CONSUME when you don’t know the topic’s schema in advance. The client retrieves the SchemaInfo from the broker and deserializes each message into a GenericRecord.

What’s next

Schema types

The full type reference and per-language mappings.

Manage schemas

Upload, retrieve, and delete schemas outside your application.
Parts of this page are adapted from the Apache Pulsar documentation, licensed under the Apache License 2.0.