platypush/plugins/google/pubsub/__init__.py
def send_message(self, topic: str, msg, **kwargs):
        """
        Sends a message to a topic

        :param 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 the
            ``topic_name`` under the ``project_id`` of your service credentials.
        :param msg: Message to be sent. It can be a list, a dict, or a Message object
        :param kwargs: Extra arguments to be passed to .publish()
        """
        # noinspection PyPackageRequirements
        from google.cloud import pubsub_v1
        # noinspection PyPackageRequirements
        from google.api_core.exceptions import AlreadyExists

        credentials = self.get_credentials(self.publisher_audience)
        publisher = pubsub_v1.PublisherClient(credentials=credentials)

        if not topic.startswith('projects/{}/topics/'.format(self.project_id)):
            topic = 'projects/{}/topics/{}'.format(self.project_id, topic)

        try:
            publisher.create_topic(topic)
        except AlreadyExists:
            pass

        if isinstance(msg, int) or isinstance(msg, float):
            msg = str(msg)
        if isinstance(msg, dict) or isinstance(msg, list):
            msg = json.dumps(msg)
        if isinstance(msg, str):
            msg = msg.encode()

        publisher.publish(topic, msg, **kwargs)

        Sends a message to a topic

        :param 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 the
            ``topic_name`` under the ``project_id`` of your service credentials.
        :param msg: Message to be sent. It can be a list, a dict, or a Message object
        :param kwargs: Extra arguments to be passed to .publish()
        
Sends a message to a topic
Sends a message to a topic
def send_message(self, topic: str, msg, **kwargs):
        from google.cloud import pubsub_v1
        from google.api_core.exceptions import AlreadyExists
        credentials = self.get_credentials(self.publisher_audience)
        publisher = pubsub_v1.PublisherClient(credentials=credentials)
        if not topic.startswith('projects/{}/topics/'.format(self.project_id)):
            topic = 'projects/{}/topics/{}'.format(self.project_id, topic)
        try:
            publisher.create_topic(topic)
        except AlreadyExists:
            pass
        if isinstance(msg, int) or isinstance(msg, float):
            msg = str(msg)
        if isinstance(msg, dict) or isinstance(msg, list):
            msg = json.dumps(msg)
        if isinstance(msg, str):
            msg = msg.encode()
        publisher.publish(topic, msg, **kwargs)
def send_message ( self , topic : str , msg , ** kwargs ) : from google . cloud import pubsub_v1 from google . api_core . exceptions import AlreadyExists credentials = self . get_credentials ( self . publisher_audience ) publisher = pubsub_v1 . PublisherClient ( credentials = credentials ) if not topic . startswith ( 'projects/{}/topics/' . format ( self . project_id ) ) : topic = 'projects/{}/topics/{}' . format ( self . project_id , topic ) try : publisher . create_topic ( topic ) except AlreadyExists : pass if isinstance ( msg , int ) or isinstance ( msg , float ) : msg = str ( msg ) if isinstance ( msg , dict ) or isinstance ( msg , list ) : msg = json . dumps ( msg ) if isinstance ( msg , str ) : msg = msg . encode ( ) publisher . publish ( topic , msg , ** kwargs )
Sends a message to a topic
Sends a message to a topic
"""
        Sends a message to a topic

        :param 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 the
            ``topic_name`` under the ``project_id`` of your service credentials.
        :param msg: Message to be sent. It can be a list, a dict, or a Message object
        :param kwargs: Extra arguments to be passed to .publish()
        """ # noinspection PyPackageRequirements # noinspection PyPackageRequirements
self
topic
str
Topic/channel where the message will be delivered. You can either specify the full topic name in
the format ``projects//topics/``, where ```` must be the ID of your
Google Pub/Sub project, or just ````  - in such case it's implied that you refer to the
``topic_name`` under the ``project_id`` of your service credentials.
Topic / channel where the message will be delivered . You can either specify the full topic name in the format ` ` projects // topics / ` ` where ` ` ` ` must be the ID of your Google Pub / Sub project or just ` ` ` ` - in such case it ' s implied that you refer to the ` ` topic_name ` ` under the ` ` project_id ` ` of your service credentials .
msg
Message to be sent. It can be a list, a dict, or a Message object
Message to be sent . It can be a list a dict or a Message object
kwargs
Extra arguments to be passed to .publish()
Extra arguments to be passed to . publish ()