Beispiel #1
0
 def _get_logentry(self, msg):
     """
     Logs the receipt of a message from the queue.
     :param msg:  kombu.transport.base.Message instance.
     :return: None
     """
     # No validation at this point so form log whatever fields you can find.
     try:
         data = json_loads(msg.body)
         data.update(msg.headers)
         fields = ['message_name', 'from', 'correlation_id', 'sequence']
         parts = ["%s: %s" % (field, data[field]) for field in fields if
                  field in data]
         if not parts:
             return "Could Not Find Values in %s" % data
         return "RECIEVED %s" % (", ".join(parts),)
     except ValueError:
         return "Could not decode msg body %r" % msg.body
Beispiel #2
0
    def _route_message(self, router, msg):
        """
        Sends the original message to the appropriate dispatcher provided by router.

        :param router:  TaskRouter instance to dispatch this message.
        :param msg: kombu.transport.base.Message to decode and dispatch.
        """
        current_time = datetime.now()
        if not self._is_alive(msg, current_time):
            msg.ack()
            raise DPNMessageError(
                "Message TTL has expired. Message headers details %s | body details %s. Current time: %s" %
                (msg.headers, msg.body, current_time)
            )

        decoded_body = json_loads(msg.body)

        try:
            message_name = decoded_body['message_name']
        except KeyError:
            raise DPNMessageError(
                "Invalid message received with no 'message_body' set!")

        router.dispatch(message_name, msg, decoded_body)