def sendToMQ(self, message): try: ctx = zmq.Context() jsons = json.loads(message) # req/rep if 'mq_request' in jsons and 'data' in jsons: cli = MQSyncReq(ctx) msg = MQMessage() msg.set_action(str(jsons['mq_request'])) msg.set_data(jsons['data']) print(u"REQ : {0}".format(msg.get())) if 'dst' in jsons: dst = str(jsons['dst']) else: dst = 'manager' res = cli.request(dst, msg.get(), timeout=10) if res: print(res.get()) cli.shutdown() del cli # pub elif 'mq_publish' in jsons and 'data' in jsons: self.pub.send_event(jsons['mq_publish'], jsons['data']) except Exception as e: print(u"Error sending mq message: {0}".format(e))