Ejemplo n.º 1
0
    def parseMsg(self, response):
        AgentLog.debug("receive msg: {0}".format(response.body))
        try:
            try:
                command = CommandFactory.getCommand(response.getDBType(), response.getAction())(self.context, response)
            except AttributeError:
                request = self.createErrorRequest(response, 'command is not exist')
                self.sender.send(request.getRequest())
                return
            # request = command.doWork()
            # self.sender.send(request.getRequest())
            data = [((), {'command': command, 'sender': self.sender})]
            reqs = threadpool.makeRequests(doWork, data)
            [SyncCMDReceiver.pool.putRequest(req) for req in reqs]

        except Exception,e:
            AgentLog.error('syncCMDReceiver.parseMsg error %s'%e)
Ejemplo n.º 2
0
class RabbitMQSender(RabbitMQWrapper):
    def __init__(self,
                 name_="RabbitMQSender",
                 host_="localhost",
                 port_=5672,
                 exchange_='exchange',
                 routing_key_='key'):
        RabbitMQWrapper.__init__(self, name_, host_, port_, exchange_, '',
                                 routing_key_)
        AgentLog.info(
            "create sender %s {host:%s, port:%d, exchange:%s, routing_key:%s}"
            % (name_, host_, port_, exchange_, routing_key_))

    def send(self, msg):
        try:
            self.channel.basic_publish(exchange=self.exchange,
                                       routing_key=self.routing_key,
                                       body=msg)
        except ConnectionClosed, e:
            self.reconnect()
            self.channel.basic_publish(exchange=self.exchange,
                                       routing_key=self.routing_key,
                                       body=msg)
        except Exception, e:
            AgentLog.error("{0} send msg:{1} error".format(self.name, msg))
        if len(msg) > 128:
            AgentLog.debug("{0} send msg: {1}".format(self.name, msg[:128]))
        else:
            AgentLog.debug("{0} send msg: {1}".format(self.name, msg))