Prerequisites
- A Pulsar cluster on StreamNative Cloud, and a client configured to connect to it. See Connect to your cluster.
- A service account with
produceandconsumepermissions on the target topic.
Primitive schemas
bytes
- Java
- Python
- Go
- C++
string
- Java
- Python
- Go
- C++
Key/value schemas
A key/value schema pairs a schema for the key with a schema for the value.-
Construct the schema, choosing an encoding type.
INLINEputs both key and value in the message payload;SEPARATEDstores the key as the message key and the value as the payload. -
Produce with it:
-
Consume with it:
Struct schemas
Avro
Pass a class and Pulsar extracts the schema definition from it.JSON
Declaring a JSON schema works the same way as Avro—useSchema.JSON instead of AvroSchema:
Protobuf
-
Generate the message class with Protobuf 3 or later:
-
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
UseAUTO_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
UseAUTO_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.