platypush.plugins.google.pubsub
¶
-
class
platypush.plugins.google.pubsub.
GooglePubsubPlugin
(credentials_file: str = '/home/blacklight/.credentials/platypush/google/pubsub.json', **kwargs)[source]¶ Send messages over a Google pub/sub instance. You’ll need a Google Cloud active project and a set of credentials to use this plugin:
Create a project on the Google Cloud console if you don’t have one already.
In the Google Cloud API console create a new service account key. Select “New Service Account”, choose the role “Pub/Sub Editor” and leave the key type as JSON.
Download the JSON service credentials file. By default platypush will look for the credentials file under ~/.credentials/platypush/google/pubsub.json.
Requires:
google-cloud-pubsub (
pip install google-cloud-pubsub
)
-
__init__
(credentials_file: str = '/home/blacklight/.credentials/platypush/google/pubsub.json', **kwargs)[source]¶ - Parameters
credentials_file – Path to the JSON credentials file for Google pub/sub (default: ~/.credentials/platypush/google/pubsub.json)
-
send_message
(topic: str, msg, **kwargs)[source]¶ Sends a message to a topic
- Parameters
topic – Topic/channel where the message will be delivered. You can either specify the full topic name in the format
projects/<project_id>/topics/<topic_name>
, where<project_id>
must be the ID of your Google Pub/Sub project, or just<topic_name>
- in such case it’s implied that you refer to thetopic_name
under theproject_id
of your service credentials.msg – Message to be sent. It can be a list, a dict, or a Message object
kwargs – Extra arguments to be passed to .publish()