示例#1
0
    async def send(self, message_type, message_content, timeout=None):
        correlation_id = uuid.uuid4().hex

        self._msg_router.expect_reply(correlation_id)

        message = Message(correlation_id=correlation_id,
                          content=message_content,
                          message_type=message_type)

        # Send the message. Backoff and retry in case of an error
        # We want a short backoff and retry attempt, so use the defaults
        # of 3 retries with 200ms of backoff
        backoff = _Backoff(max_retries=3,
                           interval=200,
                           error=SendBackoffTimeoutError())

        while True:
            try:
                await self._socket.send_multipart(
                    [message.SerializeToString()])
                break
            except asyncio.CancelledError:  # pylint: disable=try-except-raise
                raise
            except zmq.error.Again as e:
                await backoff.do_backoff(err_msg=repr(e))

        return await self._msg_router.await_reply(correlation_id,
                                                  timeout=timeout)
示例#2
0
    async def send(self, message_type, message_content, timeout=None):
        correlation_id = uuid.uuid4().hex

        self._msg_router.expect_reply(correlation_id)

        message = Message(correlation_id=correlation_id,
                          content=message_content,
                          message_type=message_type)

        try:
            await self._socket.send_multipart([message.SerializeToString()])
        except asyncio.CancelledError:
            return None

        return await self._msg_router.await_reply(correlation_id,
                                                  timeout=timeout)