Ejemplo n.º 1
0
    def process_mqtt_message(self, msg):
        msg_json, reply_body, status_code, req_id = utils.get_response_fields(
            request_msg=msg, fsencoding=self.fsencoding, is_mqtt=True)

        LOGGER.debug(f"Received message with request_id: {req_id}, mid: "
                     f"{msg.mid}, and msg json: {msg_json}")

        task_path = utils.get_task_path_from_reply_body(reply_body)
        reply_body_str = json.dumps(reply_body)
        response_json = self.form_response_json(request_id=req_id,
                                                status_code=status_code,
                                                reply_body_str=reply_body_str,
                                                task_path=task_path)

        self.send_response(response_json)
        LOGGER.debug(f'MQTT response: {response_json}')
Ejemplo n.º 2
0
    def process_amqp_message(self, properties, body, basic_deliver):
        msg_json, reply_body, status_code, req_id = utils.get_response_fields(
            request_msg=body, fsencoding=self.fsencoding, is_mqtt=False)

        if properties.reply_to is not None:
            reply_body_str = json.dumps(reply_body)
            reply_msg = self.form_response_json(request_id=req_id,
                                                status_code=status_code,
                                                reply_body_str=reply_body_str)

            self.send_response(reply_msg, properties)
            LOGGER.debug(f"Sucessfully sent reply: {reply_msg} to AMQP.")

        global REQUESTS_BEING_PROCESSED, LRU_LOCK
        LRU_LOCK.acquire()
        try:
            if req_id in REQUESTS_BEING_PROCESSED:
                del REQUESTS_BEING_PROCESSED[req_id]
        finally:
            LRU_LOCK.release()
Ejemplo n.º 3
0
    def process_mqtt_message(self, msg):
        msg_json = json.loads(msg.payload.decode(self.fsencoding))
        if msg_json.get('type', None) == 'BEHAVIOR_INVOCATION':   # noqa: E501
            self.process_behavior_message(msg_json=msg_json)
        else:
            msg_json, reply_body, status_code, req_id = utils.get_response_fields(  # noqa: E501
                request_msg=msg,
                fsencoding=self.fsencoding,
                is_mqtt=True)

            LOGGER.debug(f"Received message with request_id: {req_id}, mid: "
                         f"{msg.mid}, and msg json: {msg_json}")

            task_path = utils.get_task_path_from_reply_body(reply_body)
            reply_body_str = json.dumps(reply_body)
            response_json = self._mqtt_publisher.construct_response_json(
                request_id=req_id,
                status_code=status_code,
                reply_body_str=reply_body_str,
                task_path=task_path)

            self._mqtt_publisher.send_response(response_json)
            LOGGER.debug(f'MQTT response: {response_json}')