# PubsubMessage

- [JSON representation](https://docs.cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage#SCHEMA_REPRESENTATION)

A message that is published by publishers and consumed by subscribers. The message must contain either a non-empty data field or at least one attribute. Note that client libraries represent this object differently depending on the language. See the corresponding [client library documentation](https://cloud.google.com/pubsub/docs/reference/libraries) for more information. See [quotas and limits](https://cloud.google.com/pubsub/quotas) for more information about message limits.

| JSON representation |
|---|
| ``` { "data": string, "attributes": { string: string, ... }, "messageId": string, "publishTime": string, "orderingKey": string } ``` |

| Fields ||
|---|---|
| `data` | `string (https://developers.google.com/discovery/v1/type-format format)` Optional. The message data field. If this field is empty, the message must contain at least one attribute. A base64-encoded string. |
| `attributes` | `map (key: string, value: string)` Optional. Attributes for this message. If this field is empty, the message must contain non-empty data. This can be used to filter messages on the subscription. An object containing a list of `"key": value` pairs. Example: `{ "name": "wrench", "mass": "1.3kg", "count": "3" }`. |
| `messageId` | `string` ID of this message, assigned by the server when the message is published. Guaranteed to be unique within the topic. This value may be read by a subscriber that receives a `PubsubMessage` via a `subscriptions.pull` call or a push delivery. It must not be populated by the publisher in a `topics.publish` call. |
| `publishTime` | ``string (`https://protobuf.dev/reference/protobuf/google.protobuf#timestamp` format)`` The time at which the message was published, populated by the server when it receives the `topics.publish` call. It must not be populated by the publisher in a `topics.publish` call. Uses RFC 3339, where generated output will always be Z-normalized and use 0, 3, 6 or 9 fractional digits. Offsets other than "Z" are also accepted. Examples: `"2014-10-02T15:01:23Z"`, `"2014-10-02T15:01:23.045123456Z"` or `"2014-10-02T15:01:23+05:30"`. |
| `orderingKey` | `string` Optional. If non-empty, identifies related messages for which publish order should be respected. If a `Subscription` has `enableMessageOrdering` set to `true`, messages published with the same non-empty `orderingKey` value will be delivered to subscribers in the order in which they are received by the Pub/Sub system. All `PubsubMessage`s published in a given `PublishRequest` must specify the same `orderingKey` value. For more information, see [ordering messages](https://cloud.google.com/pubsub/docs/ordering). |