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/reference/rest/v1/PubsubMessage

Parameters:
  • data (bytes) – the payload of the message.
  • message_id (string) – An ID assigned to the message by the API.
  • attributes (dict or None) – 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 or None) – The API representation of the message
Return type:Message
Returns:The message created from the response.
service_timestamp#

Return server-set timestamp.

Return type:string
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.