123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- import datetime
- import threading
- import time
- import async_communication as CM
- import message_pb2 as message
- import google.protobuf.text_format as tf
- import CheckCommand as CHE
- from config import MQ_CONFIG as mq_config
- import sys
- sys.path.append("..")
- from log_helper.logger import HandleLog
- def check_park_command(body):
- # print("接收停车指令 %s message:%s" % (datetime.datetime.now(), body))
- log.info("接收停车指令 %s message:%s" % (datetime.datetime.now(),body[0:120]))
- cmd = checker.entrance_isOK(body)
- response_port = "user_park_command_%d_response_port" % cmd.terminal_id
- dispatch_key = ""
- if cmd.statu.execute_statu == message.eNormal:
- # 指令检查正常
- log.info("停车指令 %s OK: 车牌号:%s 检查成功!\n" % (datetime.datetime.now(), cmd.car_number))
- dispatch_key = "park_command_request_port"
- g_rabbitmq.publish(mq_config.mq_command_exchange_name, dispatch_key, tf.MessageToString(cmd, as_utf8=True))
- else:
- if cmd.statu.execute_statu == message.eWarning:
- log.warning("停车指令 %s 车牌号:%s 检查失败!\n 发送反馈 交换机:%s 发送反馈端口:%s 反馈表单:%s" % (
- datetime.datetime.now(), cmd.car_number,
- mq_config.mq_command_exchange_name, response_port + "," + dispatch_key,
- tf.MessageToString(cmd, as_utf8=True)))
- elif cmd.statu.execute_statu == message.eError:
- log.error("停车指令 %s 车牌号:%s 检查失败!\n 发送反馈 交换机:%s 发送反馈端口:%s 反馈表单:%s" % (
- datetime.datetime.now(), cmd.car_number,
- mq_config.mq_command_exchange_name, response_port + "," + dispatch_key,
- tf.MessageToString(cmd, as_utf8=True)))
- else:
- log.critical("停车指令 %s 车牌号:%s 检查失败!\n 发送反馈 交换机:%s 发送反馈端口:%s 反馈表单:%s" % (
- datetime.datetime.now(), cmd.car_number,
- mq_config.mq_command_exchange_name, response_port + "," + dispatch_key,
- tf.MessageToString(cmd, as_utf8=True)))
- g_rabbitmq.publish(mq_config.mq_command_exchange_name, response_port, tf.MessageToString(cmd, as_utf8=True))
- def check_pick_command(body):
- log.info("接收取车指令 %s message:%s" % (datetime.datetime.now(), body))
- cmd = checker.exit_isOK(body)
- response_port = "user_pick_command_%d_response_port" % cmd.terminal_id
- dispatch_key = ""
- if cmd.statu.execute_statu == message.eNormal:
- # 指令检查正常
- log.info("取车指令 %s OK : 唯一码:%s 检查成功!\n" % (datetime.datetime.now(), cmd.primary_key))
- dispatch_key = "pick_command_request_port"
- g_rabbitmq.publish(mq_config.mq_command_exchange_name, dispatch_key, tf.MessageToString(cmd, as_utf8=True))
- else:
- if cmd.statu.execute_statu == message.eWarning:
- log.warning("取车指令 %s 唯一码:%s 检查失败!\n 发送反馈 交换机:%s 发送反馈端口:%s 反馈表单:%s" % (
- datetime.datetime.now(), cmd.primary_key,
- mq_config.mq_command_exchange_name, response_port + "," + dispatch_key,
- tf.MessageToString(cmd, as_utf8=True)))
- elif cmd.statu.execute_statu == message.eError:
- log.error("取车指令 %s 唯一码:%s 检查失败!\n 发送反馈 交换机:%s 发送反馈端口:%s 反馈表单:%s" % (
- datetime.datetime.now(), cmd.primary_key,
- mq_config.mq_command_exchange_name, response_port + "," + dispatch_key,
- tf.MessageToString(cmd, as_utf8=True)))
- else:
- log.critical("取车指令 %s 唯一码:%s 检查失败!\n 发送反馈 交换机:%s 发送反馈端口:%s 反馈表单:%s" % (
- datetime.datetime.now(), cmd.primary_key,
- mq_config.mq_command_exchange_name, response_port + "," + dispatch_key,
- tf.MessageToString(cmd, as_utf8=True)))
- if cmd.terminal_id != 0:
- g_rabbitmq.publish(mq_config.mq_command_exchange_name, response_port, tf.MessageToString(cmd, as_utf8=True))
- if __name__ == '__main__':
- # 日志记录
- log = HandleLog.get_logger('.\\指令检查节点\\logs')
- # 消费指令消息
- cmd_callbacks = [["user_park_command_request_queue", check_park_command],
- ["user_pick_command_request_queue", check_pick_command]]
- print("系统初始化中...... %s " % (datetime.datetime.now()))
- checker = CHE.CommandChecker()
- print("系统初始化完成! %s " % (datetime.datetime.now()))
- g_rabbitmq = CM.RabbitAsyncCommunicator(mq_config.mq_ip, mq_config.mq_port, mq_config.mq_user, mq_config.mq_password)
- g_rabbitmq.Init(cmd_callbacks, mq_config.mq_statu_exchange_keys,"checker")
- for ex,key in mq_config.mq_statu_exchange_keys:
- g_rabbitmq.bind_statu_callback(ex,key,checker.receive_dispatch_statu)
- g_rabbitmq.start()
- g_rabbitmq.join()
|