Topics#
Define API Topics.
-
class
gcloud.pubsub.topic.Batch(topic, client)[source]# Bases:
objectContext manager: collect messages to publish via a single API call.
Helper returned by :meth:Topic.batch
Parameters: - topic (
gcloud.pubsub.topic.Topic) – the topic being published - client (
gcloud.pubsub.client.Client) – The client to use.
-
commit(client=None)[source]# Send saved messages as a single API call.
Parameters: client ( gcloud.pubsub.client.ClientorNoneType) – the client to use. If not passed, falls back to theclientstored on the current batch.
- topic (
-
class
gcloud.pubsub.topic.Topic(name, client, timestamp_messages=False)[source]# Bases:
objectTopics are targets to which messages can be published.
Subscribers then receive those messages.
See: https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/topics
Parameters: - name (string) – the name of the topic
- client (
gcloud.pubsub.client.Client) – A client which holds credentials and project configuration for the topic (which requires a project). - timestamp_messages (boolean) – If true, the topic will add a
timestampkey to the attributes of each published message: the value will be an RFC 3339 timestamp.
-
batch(client=None)[source]# Return a batch to use as a context manager.
Parameters: client ( gcloud.pubsub.client.ClientorNoneType) – the client to use. If not passed, falls back to theclientstored on the current topic.Return type: BatchReturns: A batch to use as a context manager.
-
create(client=None)[source]# API call: create the topic via a PUT request
See: https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/topics/create
Parameters: client ( gcloud.pubsub.client.ClientorNoneType) – the client to use. If not passed, falls back to theclientstored on the current topic.
-
delete(client=None)[source]# API call: delete the topic via a DELETE request
See: https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/topics/delete
Parameters: client ( gcloud.pubsub.client.ClientorNoneType) – the client to use. If not passed, falls back to theclientstored on the current topic.
-
exists(client=None)[source]# API call: test for the existence of the topic via a GET request
See https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/topics/get
Parameters: client ( gcloud.pubsub.client.ClientorNoneType) – the client to use. If not passed, falls back to theclientstored on the current topic.
-
classmethod
from_api_repr(resource, client)[source]# Factory: construct a topic given its API representation
Parameters: - resource (dict) – topic resource representation returned from the API
- client (
gcloud.pubsub.client.Client) – Client which holds credentials and project configuration for the topic.
Return type: Returns: Topic parsed from
resource.Raises: ValueErrorifclientis notNoneand the project from the resource does not agree with the project from the client.
-
full_name# Fully-qualified name used in topic / subscription APIs
-
path# URL path for the topic’s APIs
-
project# Project bound to the topic.
-
publish(message, client=None, **attrs)[source]# API call: publish a message to a topic via a POST request
See: https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/topics/publish
Parameters: - message (bytes) – the message payload
- client (
gcloud.pubsub.client.ClientorNoneType) – the client to use. If not passed, falls back to theclientstored on the current topic. - attrs (dict (string -> string)) – key-value pairs to send as message attributes
Return type: Returns: message ID assigned by the server to the published message