def publish_to_topic()

in src/ipc_pubsub/ipc_topic_pubsub.py [0:0]


    def publish_to_topic(self, topic, message_object):
        '''
            Publish a Python object sterilised as a JSON message to the requested local IPC topic.
        '''
        
        try:
            log.info('IPC PUBLISH: topic: {} - Message: {}'.format(topic, message_object))
            self.pub_request.topic = topic
            json_message = json.dumps(message_object)
            self.publish_message.binary_message.message = bytes(json_message, "utf-8")
            self.pub_request.publish_message = self.publish_message
            operation = self.ipc_publish_client.new_publish_to_topic()
            operation.activate(self.pub_request)
            future = operation.get_response()
            future.result(self.ipc_timeout)

        except KeyError as key_error: # pragma: no cover  # includes requests for fields that don't exixt in the received object
            log.error('KEY_ERROR: KeyError occurred while publishing to IPC topic. ERROR MESSAGE {} - TOPIC {} - MESSAGE: {}'.format(key_error,  topic, message_object))

        except concurrent.futures.TimeoutError as timeout_error: # pragma: no cover
            log.error('TIMEOUT_ERROR: Timeout occurred while publishing to IPC topic. ERROR MESSAGE {} - TOPIC {} - MESSAGE: {}'.format(timeout_error,  topic, message_object))

        except UnauthorizedError as unauth_error: # pragma: no cover
            log.error('UNAUTHORIZED_ERROR: Unauthorized error while publishing to IPC topic. ERROR MESSAGE {} - TOPIC {} - MESSAGE: {}'.format(unauth_error,  topic, message_object))

        except Exception as err: # pragma: no cover
            log.error('EXCEPTION: Exception while publishing to IPC topic. ERROR MESSAGE {} - TOPIC {} - MESSAGE: {}'.format(err,  topic, mesmessage_objectsage))