12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import datetime
- 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
- def check_park_command(body):
- print("接收停车指令 %s message:%s" % (datetime.datetime.now(), body))
- 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:
- # 指令检查正常
- print("停车指令 %s OK: 车牌号:%s 检查成功!" % (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:
- print("停车指令 %s ERROR: 车牌号:%s 检查失败!" % (datetime.datetime.now(), cmd.car_number))
- g_rabbitmq.publish(mq_config.mq_command_exchange_name, response_port, tf.MessageToString(cmd, as_utf8=True))
- print("交换机:%s 发送反馈端口:%s %s 反馈表单:%s" % (mq_config.mq_command_exchange_name,response_port, dispatch_key, str(cmd)))
- def check_pick_command(body):
- print("接收取车指令 %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:
- # 指令检查正常
- print("取车指令 %s OK : 唯一码:%s 检查成功!" % (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:
- print("取车指令 %s ERROR : 唯一码:%s 检查失败!" % (datetime.datetime.now(), cmd.primary_key))
- if cmd.terminal_id != 0:
- g_rabbitmq.publish(mq_config.mq_command_exchange_name, response_port, tf.MessageToString(cmd, as_utf8=True))
- print("交换机:%s 发送反馈端口:%s %s 反馈表单:%s" % (mq_config.mq_command_exchange_name,response_port, dispatch_key, str(cmd)))
- if __name__ == '__main__':
- # 消费指令消息
- cmd_callbacks = [["user_park_command_request_queue", check_park_command],
- ["user_pick_command_request_queue", check_pick_command]]
- 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")
- checker = CHE.CommandChecker()
- for ex,key in mq_config.mq_statu_exchange_keys:
- g_rabbitmq.bind_statu_callback(ex,key,checker.receive_dispatch_statu)
- g_rabbitmq.start()
|