def onMsg(self): pack = stackless.getcurrent()._fttask.pack ftlog.debug('A2AProtocol->[' + pack + ']') src, dst, queryid, userheader1, userheader2, message = agentmsg.unpack( pack) if src == None or dst == None: ftlog.info("ERROR, recive a error format message") return if self.peer_id == 0: self.peer_id = src ftcon.serverid_protocol_map[self.peer_id] = self ftlog.info("Receive other agent register, agentid=", self.peer_id) return # 处理agent服务自身的命令 if dst == ftcon.global_config[ "server_id"] and A2AProtocol.onCommand != None: # ftlog.debug('A2AProtocol-> it self command !!') A2AProtocol.onCommand(self, src, queryid, userheader1, userheader2, message) return try: # 从其他agent过来的数据,转给连接的dst service # ftlog.debug('A2AProtocol->send to target->', dst) protocol = ftcon.serverid_protocol_map[dst] protocol.transport.write(pack + '\r\n') except: ftlog.error('msg route error, dst_server_id=', dst)
def onMsg(self): pack = stackless.getcurrent()._fttask.pack ftlog.debug('A2AProtocol->[' + pack + ']') src, dst, queryid, userheader1, userheader2, message = agentmsg.unpack(pack) if src == None or dst == None: ftlog.info("ERROR, recive a error format message") return if self.peer_id == 0: self.peer_id = src ftcon.serverid_protocol_map[self.peer_id] = self ftlog.info("Receive other agent register, agentid=", self.peer_id) return # 处理agent服务自身的命令 if dst == ftcon.global_config["server_id"] and A2AProtocol.onCommand != None: # ftlog.debug('A2AProtocol-> it self command !!') A2AProtocol.onCommand(self, src, queryid, userheader1, userheader2, message) return try: # 从其他agent过来的数据,转给连接的dst service # ftlog.debug('A2AProtocol->send to target->', dst) protocol = ftcon.serverid_protocol_map[dst] protocol.transport.write(pack + '\r\n') except: ftlog.error('msg route error, dst_server_id=', dst)
def onMsg(self): pack = stackless.getcurrent()._fttask.pack ftlog.debug('A2SProtocol->[' + pack + ']') src, dst, queryid, userheader1, userheader2, message = agentmsg.unpack(pack) if src == None or dst == None: ftlog.info("ERROR, recive a error format message") return if self.peer_id == 0: self.peer_id = src ftcon.serverid_protocol_map[self.peer_id] = self ftlog.info("Receive service register, serverid=", self.peer_id, self) return # 处理agent服务自身的命令 if dst == ftcon.global_config["server_id"] and A2SProtocol.onCommand != None: # ftlog.debug('A2SProtocol-> it self command !!') A2SProtocol.onCommand(self, src, queryid, userheader1, userheader2, message) return if dst.find('AG') == 0: # 如果是直接发送给另外的一个AGENT, 那器agent就是其本身 agent_id = dst else: server_conf = ftcon.getServerConf(dst) agent_id = server_conf['agent'] try: # 从src发过来的数据,转给dst所在的agent # 如果是agent所属内部进程过来的数据, 直接转发至dst进程 if agent_id == ftcon.global_config["server_id"]: agent_id = dst # ftlog.debug('A2SProtocol->send to agentid->', agent_id, 'dst=', dst) protocol = ftcon.serverid_protocol_map[agent_id] protocol.transport.write(pack + '\r\n') except: ftlog.error('msg route error, not found agent protocol, dst_server_id=', dst, 'agend=', agent_id)
def lineReceived(self, data): ftlog.debug('S2AProtocol->lineReceived', data) src, dst, query_id, userheader1, userheader2, msg = agentmsg.unpack(data) if src == None or dst == None: ftlog.info("ERROR, recive a error format message") return if self.peer_id == 0: self.peer_id = src ftcon.serverid_protocol_map[self.peer_id] = self ftlog.info('receive register, agentid=', self.peer_id) return _countProtocolPack(1, self) # send过来的数据 if query_id == '': self._runTasklet(data=msg, src=src, dst=dst, userheader1=userheader1, userheader2=userheader2) else: querysrc, _ = query_id.split('.') server_id = ftcon.global_config["server_id"] # query本服务的请求 if querysrc != server_id: self._runTasklet(data=msg, src=src, dst=dst, query_id=query_id, userheader1=userheader1, userheader2=userheader2) # response回来的请求 else: if userheader1 == 'RQ': # 本进程内, 异步查询本进程的其他消息接口 self._runTasklet(data=msg, src=src, dst=dst, query_id=query_id, userheader1=userheader1, userheader2=userheader2) else: d, c = None, None # ftlog.debug('lineReceived', query_id, id(_LIVE_MESSAGES), id(self)) if query_id in _LIVE_MESSAGES: d, c = _LIVE_MESSAGES[query_id] del _LIVE_MESSAGES[query_id] else: if query_id in _FAILED_MESSAGES: del _FAILED_MESSAGES[query_id] ftlog.warn('QUERY TOO SLOW !!', query_id, msg, 'left bad querids=', _FAILED_MESSAGES) if len(_FAILED_MESSAGES) > 100: _FAILED_MESSAGES.clear() else: ftlog.warn('NOT KNOW of query_id->', query_id, msg) if d and c: try: c.cancel() d.callback(msg) except: ftlog.error(msg)