Topics may use schemas to define a format that their messages must follow. When subscribing to a topic with a schema, the messages sent to the subscriber are guaranteed to be valid messages. These messages conform to the type and encoding specified in the schema settings associated with the topic.
The subscriber can determine the schema settings associated with a topic by looking at the following attributes:
googclient_schemaname: The name of the schema used for validation. If the schema is deleted, the name is_deleted-schema_.googclient_schemaencoding: The encoding of the message, either JSON or BINARY.googclient_schemarevisionid: The revision ID of the schema used to parse and validate the message. Each revision has a unique revision ID associated with it. The revision ID is an auto-generated eight-character UUID. If the revision is deleted, the ID is_deleted-schema-revision_.
To learn more about schemas, see Schema overview.
Code samples for subscribing to topics associated with a schema
These samples show how to process messages when subscribing to topics configured with schema.
C++
Before trying this sample, follow the C++ setup instructions in Quickstart: Using Client Libraries. For more information, see the Pub/Sub C++ API reference documentation.
Avro