def _initMsg_Swap(useMQ=False): if (gol._Get_Setting('dirMsgsSwaps', None) == None): gol._Set_Setting( 'dirMsgsSwaps', "D:/myCode/zxcProj/src/Zxc.Python/zxcPy.Weixin/Data/Swaps" ) #实例 消息缓存 gol._Set_Setting('bufferMsgs', myMsgs("zxc", "zxc", "", "")) #实例 消息缓存 gol._Set_Setting('manageMsgs', myManager_Msg()) #实例 消息管理器并初始消息api及消息队列 if (useMQ): gol._Get_Setting('manageMsgs', None)._Init_MQ(plat=myMsgPlat.robot, msgMQ_Sender=myMQ_Rabbit.myMQ_Rabbit( True, 'zxcMQ_robot'), msgUrl_API="") #不使用api回调 gol._Get_Setting('manageMsgs', None)._Init_MQ(plat=myMsgPlat.wx, msgMQ_Sender=myMQ_Rabbit.myMQ_Rabbit( True, 'zxcMQ_wx'), msgUrl_API="", usrHelper='filehelper') #不使用api回调 gol._Get_Setting('manageMsgs', None)._Init_MQ(plat=myMsgPlat.usrWin, msgMQ_Sender=myMQ_Rabbit.myMQ_Rabbit( True, 'zxcMQ_usrWin'), msgUrl_API="", isAuto_ack=True) #不使用api回调 else: dirMsgsSwaps = gol._Get_Setting('dirMsgsSwaps') pDataSwap_In = myData_Swap.myData_Swap_FileIO("msgWx", dirMsgsSwaps + "/SwapMsg", stepSwaps=1, delayedTime=0, useAck=True, nameSwap="zxcSwap_wx") gol._Get_Setting('manageMsgs')._Init_Swap(plat=myMsgPlat.wx, msgSwap_Sender=pDataSwap_In, isAuto_ack=True, msgUrl_API="") pass
def _Init_MQ(self, bStart=True): #初始消息接收队列 self.mqName = 'zxcMQ_robot' if (self.mqRecv == None): self.mqRecv = myMQ_Rabbit.myMQ_Rabbit(False) self.mqRecv.Init_Queue(self.mqName, True) self.mqRecv.Init_callback_RecvMsg(self.callback_RecvMsg) #消息接收回调 myDebug.Print("消息队列(" + self.mqName + ")创建成功...") #接收消息 if (bStart): self.mqRecv.Start()
def init_MQ(self, bStart=False): #初始消息接收队列 self.mqName = 'zxcMQ_usrWin' if (self.mqRecv == None): self.mqRecv = myMQ_Rabbit.myMQ_Rabbit(False) self.mqRecv.Init_Queue(self.mqName, True) self.mqRecv.Init_callback_RecvMsg(self.callback_RecvMsg) #消息接收回调 myDebug.Print("消息队列(" + self.mqName + ")创建成功...") #接收消息 if (bStart): self.mqRecv.Start() self.mqTimeNow = myData_Trans.Tran_ToTime_int() #接收开始时间
def Init_MQ(self, bStart=False): if (gol._Get_Value("msgSet_usrMQ", False) == False): self.Init_Swap(bStart) return #初始消息接收队列 self.mqName = 'zxcMQ_wx' if (self.mqRecv == None): self.mqRecv = myMQ_Rabbit.myMQ_Rabbit(False) self.mqRecv.Init_Queue(self.mqName, True) self.mqRecv.Init_callback_RecvMsg(self.callback_RecvMsg) #消息接收回调 myDebug.Print("消息队列(" + self.mqName + ")创建成功...") #接收消息 if (bStart): self.mqRecv.Start() self.mqTimeNow = myData_Trans.Tran_ToTime_int() #接收开始时间
#生成命令并推送消息队列 msg = {'usrName': user, 'msg': text, 'msgType': type} pMQ_Sender.Send_Msg(pMQ_Sender.nameQueue, str(msg)) myDebug.Debug(pMQ_Sender.nameQueue, msg) try: return True except : return False #主程序启动 if __name__ == '__main__': # 创建消息队列 gol._Init() #先必须在主模块初始化(只在Main模块需要一次即可) nameMQ = 'zxcMQ_wx' pMQ_Sender = myMQ_Rabbit.myMQ_Rabbit(True) pMQ_Sender.Init_Queue(nameMQ, True) gol._Set_Value('zxcMQ_Wx_Sender', pMQ_Sender, True) errStr = "创建消息队列失败." pMQ = myAPI_Weixin_Cmd_ByMQ() pMQ.get('茶叶一主号','text--登陆') # 创建内存映射 try: pMMap_Manager = myMMap.myMMap_Manager("D:\myGit\zxcProj\src\Zxc.Python\zxcPy.Weixin\Data/zxcMMap.dat") ind = 0 while(True): dict0 = {'usrName': '茶叶一主号', 'msg': 'text--登陆', 'msgType': 'Text'}
def Check_TimeOut(self, msg, nTimeOut = 600, nTimeNow = -1): #时间校检, 十分钟内缓存数据有效(过早时间数据忽略) msgTime = msg.get('time', -1) if(nTimeNow < 0): nTimeNow = myData_Trans.Tran_ToTime_int() if(abs(msgTime - nTimeNow) >= 600): myDebug.Warnning("已超时::", nTimeNow, ",", msgTime) return True return False #初始全局消息管理器 from myGlobal import gol gol._Init() #先必须在主模块初始化(只在Main模块需要一次即可) gol._Set_Setting('bufferMsgs', myMsgs("zxc", "zxc", "", "")) #实例 消息缓存 gol._Set_Setting('manageMsgs', myManager_Msg()) #实例 消息管理器并初始消息api及消息队列 gol._Get_Setting('manageMsgs', None)._Init(plat = myMsgPlat.robot, msgMQ_Sender = myMQ_Rabbit.myMQ_Rabbit(True, 'zxcMQ_robot'), msgUrl_API = "") #不使用api回调 gol._Get_Setting('manageMsgs', None)._Init(plat = myMsgPlat.wx, msgMQ_Sender = myMQ_Rabbit.myMQ_Rabbit(True, 'zxcMQ_wx'), msgUrl_API = "", usrHelper = 'filehelper') #不使用api回调 if __name__ == '__main__': pMMsg = gol._Get_Setting('manageMsgs') pMMsg.Init_LogDir("D:/myGit/zxcProj/src/Zxc.Python/zxcPy.Robot/Log/Msgs/") #组装消息 msg = pMMsg.OnCreatMsg() msg["usrName"] = "茶叶一主号" msg["usrID"] = "zxcID" msg["msg"] = "测试消息py" msg["msgID"] = "msgID-***" msg["msgType"] = "TEXT" msg["usrPlat"] = "wx"
MQ 消息队列操作 """ import sys, time, pika, threading from atexit import register from myMQ_Rabbit import myMQ_Rabbit class myMQ_Rabbit_Recv: #定义消息接收方法,外部可重写@register def Recv_Msg(self, body): print("[消费者] Recv_Msg %s" % body) return True if __name__ == '__main__': #实例生产者、消费者 nameMQ = 'zxcTest' pMQ_Recv = myMQ_Rabbit(False) pMQ_Recv.Init_Queue(nameMQ, True) p = myMQ_Rabbit_Recv() pMQ_Recv.Init_callback_RecvMsg(p.Recv_Msg) #接收消息线程--第二消息接收顺序有问题 thrdMQ = threading.Thread(target=pMQ_Recv.Start) thrdMQ.setDaemon(False) thrdMQ.start() print()