Пример #1
0
    def send(self, message: Message):
        """Send message.

        Args:
            message (class): Message to be sent.
        """
        try:
            self._unicast_sender_dict[message.destination].send_pyobj(message)
            self._logger.debug(
                f"Send a {message.tag} message to {message.destination}.")
        except Exception as e:
            return DriverSendError(f"Failure to send message caused by: {e}")
Пример #2
0
    def broadcast(self, message: Message):
        """Broadcast message.

        Args:
            message(class): Message to be sent.
        """
        try:
            self._broadcast_sender.send_pyobj(message)
            self._logger.debug(
                f"Broadcast a {message.tag} message to all subscribers.")
        except Exception as e:
            return DriverSendError(
                f"Failure to broadcast message caused by: {e}")
Пример #3
0
    def broadcast(self, topic: str, message: Message):
        """Broadcast message.

        Args:
            topic(str): The topic of broadcast.
            message(class): Message to be sent.
        """
        try:
            self._broadcast_sender.send_multipart(
                [topic.encode(), pickle.dumps(message)])
            self._logger.debug(
                f"Broadcast a {message.tag} message to all {topic}.")
        except Exception as e:
            raise DriverSendError(
                f"Failure to broadcast message caused by: {e}")
Пример #4
0
    def send(self, message: Message):
        """Send message.

        Args:
            message (class): Message to be sent.
        """
        try:
            self._unicast_sender_dict[message.destination].send_pyobj(message)
            self._logger.debug(
                f"Send a {message.tag} message to {message.destination}.")
        except KeyError as key_error:
            if message.destination in self._disconnected_peer_name_list:
                raise PendingToSend(
                    f"Temporary failure to send message to {message.destination}, may rejoin later."
                )
            else:
                self._logger.error(
                    f"Failure to send message caused by: {key_error}")
                sys.exit(NON_RESTART_EXIT_CODE)
        except Exception as e:
            raise DriverSendError(f"Failure to send message caused by: {e}")