Пример #1
0
    def send(self, target, ctxt, message,
             wait_for_reply=False, timeout=None, envelope=False,
             retry=None):
        """Send a message to the given target.

        :param target: destination for message
        :type target: oslo_messaging.Target
        :param ctxt: message context
        :type ctxt: dict
        :param message: message payload
        :type message: dict
        :param wait_for_reply: expects a reply message, wait for it
        :type wait_for_reply: bool
        :param timeout: raise exception if send does not complete within
                        timeout seconds. None == no timeout.
        :type timeout: float
        :param envelope: Encapsulate message in an envelope
        :type envelope: bool
        :param retry: (optional) maximum re-send attempts on recoverable error
                      None or -1 means to retry forever
                      0 means no retry
                      N means N retries
        :type retry: int
"""
        request = marshal_request(message, ctxt, envelope)
        expire = 0
        if timeout:
            expire = compute_timeout(timeout)  # when the caller times out
            # amqp uses millisecond time values, timeout is seconds
            request.ttl = int(timeout * 1000)
            request.expiry_time = int(expire * 1000)
        else:
            # no timeout provided by application.  If the backend is queueless
            # this could lead to a hang - provide a default to prevent this
            # TODO(kgiusti) only do this if brokerless backend
            expire = compute_timeout(self._default_send_timeout)
        if wait_for_reply:
            ack = not self._pre_settle_call
            task = controller.RPCCallTask(target, request, expire, retry)
        else:
            ack = not self._pre_settle_cast
            task = controller.SendTask("RPC Cast", request, target, expire,
                                       retry, wait_for_ack=ack)
        self._ctrl.add_task(task)

        reply = task.wait()
        if isinstance(reply, Exception):
            raise reply
        if reply:
            # TODO(kgiusti) how to handle failure to un-marshal?
            # Must log, and determine best way to communicate this failure
            # back up to the caller
            reply = unmarshal_response(reply, self._allowed_remote_exmods)
        return reply
Пример #2
0
    def send_notification(self, target, ctxt, message, version,
                          retry=None):
        """Send a notification message to the given target.

        :param target: destination for message
        :type target: oslo_messaging.Target
        :param ctxt: message context
        :type ctxt: dict
        :param message: message payload
        :type message: dict
        :param version: message envelope version
        :type version: float
        :param retry: (optional) maximum re-send attempts on recoverable error
                      None or -1 means to retry forever
                      0 means no retry
                      N means N retries
        :type retry: int
        """
        request = marshal_request(message, ctxt, envelope=(version == 2.0))
        # no timeout is applied to notifications, however if the backend is
        # queueless this could lead to a hang - provide a default to prevent
        # this
        # TODO(kgiusti) should raise NotImplemented if not broker backend
        deadline = compute_timeout(self._default_notify_timeout)
        ack = not self._pre_settle_notify
        task = controller.SendTask("Notify", request, target,
                                   deadline, retry, wait_for_ack=ack,
                                   notification=True)
        self._ctrl.add_task(task)
        rc = task.wait()
        if isinstance(rc, Exception):
            raise rc
Пример #3
0
    def send_notification(self, target, ctxt, message, version, retry=None):
        """Send a notification message to the given target.

        :param target: destination for message
        :type target: oslo_messaging.Target
        :param ctxt: message context
        :type ctxt: dict
        :param message: message payload
        :type message: dict
        :param version: message envelope version
        :type version: float
        :param retry: (optional) maximum re-send attempts on recoverable error
                      None or -1 means to retry forever
                      0 means no retry
                      N means N retries
        :type retry: int
        """
        request = marshal_request(message, ctxt, envelope=(version == 2.0))
        # no timeout is applied to notifications, however if the backend is
        # queueless this could lead to a hang - provide a default to prevent
        # this
        # TODO(kgiusti) should raise NotImplemented if not broker backend
        deadline = compute_timeout(self._default_notify_timeout)
        ack = not self._pre_settle_notify
        task = controller.SendTask("Notify",
                                   request,
                                   target,
                                   deadline,
                                   retry,
                                   wait_for_ack=ack,
                                   notification=True)
        self._ctrl.add_task(task)
        rc = task.wait()
        if isinstance(rc, Exception):
            raise rc
Пример #4
0
 def reply(self, reply=None, failure=None):
     """Schedule an RPCReplyTask to send the reply."""
     if self._reply_to:
         response = marshal_response(reply, failure)
         response.correlation_id = self._correlation_id
         LOG.debug("Sending RPC reply to %s (%s)", self._reply_to,
                   self._correlation_id)
         driver = self.listener.driver
         deadline = compute_timeout(driver._default_reply_timeout)
         ack = not driver._pre_settle_reply
         task = controller.SendTask(
             "RPC Reply",
             response,
             self._reply_to,
             # analogous to kombu missing dest t/o:
             deadline,
             retry=0,
             wait_for_ack=ack)
         driver._ctrl.add_task(task)
         rc = task.wait()
         if rc:
             # something failed.  Not much we can do at this point but log
             LOG.debug("Reply failed to send: %s", str(rc))
     else:
         LOG.debug("Ignoring reply as no reply address available")
Пример #5
0
 def reply(self, reply=None, failure=None):
     """Schedule an RPCReplyTask to send the reply."""
     if self._reply_to:
         response = marshal_response(reply, failure)
         response.correlation_id = self._correlation_id
         driver = self.listener.driver
         deadline = compute_timeout(driver._default_reply_timeout)
         ack = not driver._pre_settle_reply
         task = controller.SendTask("RPC Reply", response, self._reply_to,
                                    # analogous to kombu missing dest t/o:
                                    deadline,
                                    retry=driver._default_reply_retry,
                                    wait_for_ack=ack)
         driver._ctrl.add_task(task)
         rc = task.wait()
         if rc:
             # something failed.  Not much we can do at this point but log
             LOG.debug("RPC Reply failed to send: %s", str(rc))
     else:
         LOG.debug("Ignoring reply as no reply address available")
Пример #6
0
    def send(self,
             target,
             ctxt,
             message,
             wait_for_reply=False,
             timeout=None,
             call_monitor_timeout=None,
             retry=None):
        """Send a message to the given target.

        :param target: destination for message
        :type target: oslo_messaging.Target
        :param ctxt: message context
        :type ctxt: dict
        :param message: message payload
        :type message: dict
        :param wait_for_reply: expects a reply message, wait for it
        :type wait_for_reply: bool
        :param timeout: raise exception if send does not complete within
                        timeout seconds. None == no timeout.
        :type timeout: float
        :param call_monitor_timeout: Maximum time the client will wait for the
            call to complete or receive a message heartbeat indicating the
            remote side is still executing.
        :type call_monitor_timeout: float
        :param retry: (optional) maximum re-send attempts on recoverable error
                      None or -1 means to retry forever
                      0 means no retry
                      N means N retries
        :type retry: int
        """
        request = marshal_request(message, ctxt, None, call_monitor_timeout)
        if timeout:
            expire = compute_timeout(timeout)
            request.ttl = timeout
            request.expiry_time = compute_timeout(timeout)
        else:
            # no timeout provided by application.  If the backend is queueless
            # this could lead to a hang - provide a default to prevent this
            # TODO(kgiusti) only do this if brokerless backend
            expire = compute_timeout(self._default_send_timeout)
        if wait_for_reply:
            ack = not self._pre_settle_call
            if call_monitor_timeout is None:
                task = controller.RPCCallTask(target,
                                              request,
                                              expire,
                                              retry,
                                              wait_for_ack=ack)
            else:
                task = controller.RPCMonitoredCallTask(target,
                                                       request,
                                                       expire,
                                                       call_monitor_timeout,
                                                       retry,
                                                       wait_for_ack=ack)
        else:
            ack = not self._pre_settle_cast
            task = controller.SendTask("RPC Cast",
                                       request,
                                       target,
                                       expire,
                                       retry,
                                       wait_for_ack=ack)
        self._ctrl.add_task(task)

        reply = task.wait()
        if isinstance(reply, Exception):
            raise reply
        if reply:
            # TODO(kgiusti) how to handle failure to un-marshal?
            # Must log, and determine best way to communicate this failure
            # back up to the caller
            reply = unmarshal_response(reply, self._allowed_remote_exmods)
        return reply
Пример #7
0
    def send(self,
             target,
             ctxt,
             message,
             wait_for_reply=False,
             timeout=None,
             envelope=False,
             retry=None):
        """Send a message to the given target.

        :param target: destination for message
        :type target: oslo_messaging.Target
        :param ctxt: message context
        :type ctxt: dict
        :param message: message payload
        :type message: dict
        :param wait_for_reply: expects a reply message, wait for it
        :type wait_for_reply: bool
        :param timeout: raise exception if send does not complete within
                        timeout seconds. None == no timeout.
        :type timeout: float
        :param envelope: Encapsulate message in an envelope
        :type envelope: bool
        :param retry: (optional) maximum re-send attempts on recoverable error
                      None or -1 means to retry forever
                      0 means no retry
                      N means N retries
        :type retry: int
"""
        request = marshal_request(message, ctxt, envelope)
        expire = 0
        if timeout:
            expire = compute_timeout(timeout)  # when the caller times out
            # amqp uses millisecond time values, timeout is seconds
            request.ttl = int(timeout * 1000)
            request.expiry_time = int(expire * 1000)
        else:
            # no timeout provided by application.  If the backend is queueless
            # this could lead to a hang - provide a default to prevent this
            # TODO(kgiusti) only do this if brokerless backend
            expire = compute_timeout(self._default_send_timeout)
        LOG.debug("Sending message to %s", target)
        if wait_for_reply:
            task = controller.RPCCallTask(target, request, expire, retry)
        else:
            task = controller.SendTask("RPC Cast",
                                       request,
                                       target,
                                       expire,
                                       retry,
                                       wait_for_ack=True)
        self._ctrl.add_task(task)

        reply = task.wait()
        if isinstance(reply, Exception):
            raise reply
        if reply:
            # TODO(kgiusti) how to handle failure to un-marshal?
            # Must log, and determine best way to communicate this failure
            # back up to the caller
            reply = unmarshal_response(reply, self._allowed_remote_exmods)
        LOG.debug("Send to %s returning", target)
        return reply