Message#

Define API Topics.

class google.cloud.pubsub.message.Message(data, message_id, attributes=None)[source]#

Bases: object

Messages can be published to a topic and received by subscribers.

See: https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage

Parameters:
  • data (bytes) – the payload of the message.
  • message_id (str) – An ID assigned to the message by the API.
  • attributes (dict) – (Optional) Extra metadata associated by the publisher with the message.
attributes#

Lazily-constructed attribute dictionary.

classmethod from_api_repr(api_repr)[source]#

Factory: construct message from API representation.

Parameters:api_repr (dict) – (Optional) The API representation of the message
Return type:Message
Returns:The message created from the response.
service_timestamp#

Return server-set timestamp.

Return type:str
Returns:timestamp (in UTC timezone) in RFC 3339 format
timestamp#

Return sortable timestamp from attributes, if passed.

Allows sorting messages in publication order (assuming consistent clocks across all publishers).

Return type:datetime.datetime
Returns:timestamp (in UTC timezone) parsed from RFC 3339 timestamp
Raises:ValueError if timestamp not in attributes, or if it does not match the RFC 3339 format.