Reference documentation and code samples for the Cloud PubSub V1 Client class PubsubMessage.
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 correspondingclient library
documentationfor
more information. Seequotas and limitsfor more information about message
limits.
Generated from protobuf messagegoogle.pubsub.v1.PubsubMessage
Namespace
Google \ Cloud \ PubSub \ V1
Methods
__construct
Constructor.
Parameters
Name
Description
data
array
Optional. Data for populating the Message object.
↳ data
string
Optional. The message data field. If this field is empty, the message must contain at least one attribute.
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.
↳ message_id
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 aPubsubMessagevia aPullcall or a push delivery. It must not be populated by the publisher in aPublishcall.
The time at which the message was published, populated by the server when it receives thePublishcall. It must not be populated by the publisher in aPublishcall.
↳ ordering_key
string
Optional. If non-empty, identifies related messages for which publish order should be respected. If aSubscriptionhasenable_message_orderingset totrue, messages published with the same non-emptyordering_keyvalue will be delivered to subscribers in the order in which they are received by the Pub/Sub system. AllPubsubMessages published in a givenPublishRequestmust specify the sameordering_keyvalue. For more information, seeordering messages.
getData
Optional. The message data field. If this field is empty, the message must
contain at least one attribute.
Returns
Type
Description
string
setData
Optional. The message data field. If this field is empty, the message must
contain at least one attribute.
Parameter
Name
Description
var
string
Returns
Type
Description
$this
getAttributes
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.
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.
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 aPubsubMessagevia aPullcall or a push
delivery. It must not be populated by the publisher in aPublishcall.
Returns
Type
Description
string
setMessageId
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 aPubsubMessagevia aPullcall or a push
delivery. It must not be populated by the publisher in aPublishcall.
Parameter
Name
Description
var
string
Returns
Type
Description
$this
getPublishTime
The time at which the message was published, populated by the server when
it receives thePublishcall. It must not be populated by the
publisher in aPublishcall.
The time at which the message was published, populated by the server when
it receives thePublishcall. It must not be populated by the
publisher in aPublishcall.
Optional. If non-empty, identifies related messages for which publish order
should be respected. If aSubscriptionhasenable_message_orderingset
totrue, messages published with the same non-emptyordering_keyvalue
will be delivered to subscribers in the order in which they are received by
the Pub/Sub system. AllPubsubMessages published in a givenPublishRequestmust specify the sameordering_keyvalue. For more
information, seeordering
messages.
Returns
Type
Description
string
setOrderingKey
Optional. If non-empty, identifies related messages for which publish order
should be respected. If aSubscriptionhasenable_message_orderingset
totrue, messages published with the same non-emptyordering_keyvalue
will be delivered to subscribers in the order in which they are received by
the Pub/Sub system. AllPubsubMessages published in a givenPublishRequestmust specify the sameordering_keyvalue. For more
information, seeordering
messages.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Cloud PubSub V1 Client - Class PubsubMessage (2.13.2)\n\nVersion latestkeyboard_arrow_down\n\n- [2.13.2 (latest)](/php/docs/reference/cloud-pubsub/latest/V1.PubsubMessage)\n- [2.13.1](/php/docs/reference/cloud-pubsub/2.13.1/V1.PubsubMessage)\n- [2.12.0](/php/docs/reference/cloud-pubsub/2.12.0/V1.PubsubMessage)\n- [2.11.3](/php/docs/reference/cloud-pubsub/2.11.3/V1.PubsubMessage)\n- [2.10.1](/php/docs/reference/cloud-pubsub/2.10.1/V1.PubsubMessage)\n- [2.9.1](/php/docs/reference/cloud-pubsub/2.9.1/V1.PubsubMessage)\n- [2.8.2](/php/docs/reference/cloud-pubsub/2.8.2/V1.PubsubMessage)\n- [2.7.0](/php/docs/reference/cloud-pubsub/2.7.0/V1.PubsubMessage)\n- [2.6.0](/php/docs/reference/cloud-pubsub/2.6.0/V1.PubsubMessage)\n- [2.5.2](/php/docs/reference/cloud-pubsub/2.5.2/V1.PubsubMessage)\n- [2.4.0](/php/docs/reference/cloud-pubsub/2.4.0/V1.PubsubMessage)\n- [2.3.0](/php/docs/reference/cloud-pubsub/2.3.0/V1.PubsubMessage)\n- [2.2.1](/php/docs/reference/cloud-pubsub/2.2.1/V1.PubsubMessage)\n- [2.1.2](/php/docs/reference/cloud-pubsub/2.1.2/V1.PubsubMessage)\n- [1.50.0](/php/docs/reference/cloud-pubsub/1.50.0/V1.PubsubMessage)\n- [1.49.0](/php/docs/reference/cloud-pubsub/1.49.0/V1.PubsubMessage)\n- [1.48.0](/php/docs/reference/cloud-pubsub/1.48.0/V1.PubsubMessage)\n- [1.47.0](/php/docs/reference/cloud-pubsub/1.47.0/V1.PubsubMessage)\n- [1.46.5](/php/docs/reference/cloud-pubsub/1.46.5/V1.PubsubMessage)\n- [1.45.2](/php/docs/reference/cloud-pubsub/1.45.2/V1.PubsubMessage)\n- [1.44.0](/php/docs/reference/cloud-pubsub/1.44.0/V1.PubsubMessage)\n- [1.43.2](/php/docs/reference/cloud-pubsub/1.43.2/V1.PubsubMessage)\n- [1.42.1](/php/docs/reference/cloud-pubsub/1.42.1/V1.PubsubMessage)\n- [1.41.3](/php/docs/reference/cloud-pubsub/1.41.3/V1.PubsubMessage)\n- [1.40.1](/php/docs/reference/cloud-pubsub/1.40.1/V1.PubsubMessage)\n- [1.39.3](/php/docs/reference/cloud-pubsub/1.39.3/V1.PubsubMessage) \nReference documentation and code samples for the Cloud PubSub V1 Client class PubsubMessage.\n\nA message that is published by publishers and consumed by subscribers. The\nmessage must contain either a non-empty data field or at least one attribute.\n\nNote that client libraries represent this object differently\ndepending on the language. See the corresponding [client library\ndocumentation](https://cloud.google.com/pubsub/docs/reference/libraries) for\nmore information. See [quotas and limits](https://cloud.google.com/pubsub/quotas) for more information about message\nlimits.\n\nGenerated from protobuf message `google.pubsub.v1.PubsubMessage`\n\nNamespace\n---------\n\nGoogle \\\\ Cloud \\\\ PubSub \\\\ V1\n\nMethods\n-------\n\n### __construct\n\nConstructor.\n\n### getData\n\nOptional. The message data field. If this field is empty, the message must\ncontain at least one attribute.\n\n### setData\n\nOptional. The message data field. If this field is empty, the message must\ncontain at least one attribute.\n\n### getAttributes\n\nOptional. Attributes for this message. If this field is empty, the message\nmust contain non-empty data. This can be used to filter messages on the\nsubscription.\n\n### setAttributes\n\nOptional. Attributes for this message. If this field is empty, the message\nmust contain non-empty data. This can be used to filter messages on the\nsubscription.\n\n### getMessageId\n\nID of this message, assigned by the server when the message is published.\n\nGuaranteed to be unique within the topic. This value may be read by a\nsubscriber that receives a `PubsubMessage` via a `Pull` call or a push\ndelivery. It must not be populated by the publisher in a `Publish` call.\n\n### setMessageId\n\nID of this message, assigned by the server when the message is published.\n\nGuaranteed to be unique within the topic. This value may be read by a\nsubscriber that receives a `PubsubMessage` via a `Pull` call or a push\ndelivery. It must not be populated by the publisher in a `Publish` call.\n\n### getPublishTime\n\nThe time at which the message was published, populated by the server when\nit receives the `Publish` call. It must not be populated by the\npublisher in a `Publish` call.\n\n### hasPublishTime\n\n### clearPublishTime\n\n### setPublishTime\n\nThe time at which the message was published, populated by the server when\nit receives the `Publish` call. It must not be populated by the\npublisher in a `Publish` call.\n\n### getOrderingKey\n\nOptional. If non-empty, identifies related messages for which publish order\nshould be respected. If a `Subscription` has `enable_message_ordering` set\nto `true`, messages published with the same non-empty `ordering_key` value\nwill be delivered to subscribers in the order in which they are received by\nthe Pub/Sub system. All `PubsubMessage`s published in a given\n`PublishRequest` must specify the same `ordering_key` value. For more\ninformation, see [ordering\nmessages](https://cloud.google.com/pubsub/docs/ordering).\n\n### setOrderingKey\n\nOptional. If non-empty, identifies related messages for which publish order\nshould be respected. If a `Subscription` has `enable_message_ordering` set\nto `true`, messages published with the same non-empty `ordering_key` value\nwill be delivered to subscribers in the order in which they are received by\nthe Pub/Sub system. All `PubsubMessage`s published in a given\n`PublishRequest` must specify the same `ordering_key` value. For more\ninformation, see [ordering\nmessages](https://cloud.google.com/pubsub/docs/ordering)."]]