Python
Topics#
Define API Topics.
-
class
gcloud.pubsub.topic.
Topic
(name, project=None, connection=None)[source]# Bases:
object
Topics 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
- project (string) – the project to which the topic belongs. If not passed, falls back to the default inferred from the environment.
- connection (:class:gcloud.pubsub.connection.Connection) – the connection to use. If not passed, falls back to the default inferred from the environment.
-
create
()[source]# API call: create the topic via a PUT request
See: https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/topics/create
-
delete
()[source]# API call: delete the topic via a DELETE request
See: https://cloud.google.com/pubsub/reference/rest/v1beta2/projects/topics/delete
-
exists
()[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
-
classmethod
from_api_repr
(resource, connection=None)[source]# Factory: construct a topic given its API representation
Parameters: - resource (dict) – topic resource representation returned from the API
- connection (
gcloud.pubsub.connection.Connection
or None) – the connection to use. If not passed, falls back to the default inferred from the environment.
Return type:
-
full_name
# Fully-qualified name used in topic / subscription APIs
-
path
# URL path for the topic’s APIs
-
publish
(message, **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 Message attrs: key-value pairs to send as message attributes Return type: str Returns: message ID assigned by the server to the published message