This document shows you how to publish messages to a topic with a schema.
Before you begin
Before configuring the publish workflow, ensure you have completed the following tasks:
- Understand how Pub/Sub schemas work.
- Associate a schema with a topic.
Required roles
To get the permissions that
you need to publish messages to a topic,
ask your administrator to grant you the
Pub/Sub Publisher (roles/pubsub.publisher) IAM role on the topic.
For more information about granting roles, see Manage access to projects, folders, and organizations.
You might also be able to get the required permissions through custom roles or other predefined roles.
You need additional permissions to create or update topics and subscriptions.Publish messages with schema
You can publish messages to a topic that is associated with a schema. You must encode the messages in the schema and format that you specified when you created the topic. A message matches the schema associated with the topic if it matches any of the schema's revision in the allowed range of revisions. Messages are evaluated against revisions in order from the most recent allowed revision until either a match is found or the oldest allowed revision is reached. Pub/Sub adds the following attributes to a message successfully published to a topic associated with a schema:
googclient_schemaname: The name of the schema used for validation.googclient_schemaencoding: The encoding of the message, either JSON or BINARY.