예제 #1
0
파일: beanstalk.py 프로젝트: yamingd/play
 def send(self, messages):
     self.connect()
     if not self.pool:
         raise Exception('can not connect beanstalk server.')
     if not isinstance(messages, list):
         messages = list(messages)
     total = 0
     with self.pool.reserve() as conn:
         for message in messages:
             try:
                 ttr = message.get('ttr', 60)
                 conn.use(message.queue.name)
                 conn.put(jsonfy.dumps(message), ttr=int(ttr))
                 self.count = self.count + 1
                 total = total + 1
                 log.debug('mq message count:%s' % self.count)
             except:
                 log.exception('unexpected error')
     return total
예제 #2
0
파일: rabbitmq.py 프로젝트: yamingd/play
 def send(self, messages):
     self.connect()
     if not self.connection:
         raise Exception("RabbitMQ can't connect to server.")
     if not isinstance(messages, list):
         messages = list(messages)
     total = 0
     with self.pool.reserve() as c:
         for message in messages:
             try:
                 exchange_name = message.queue.exchange
                 routing_key = message.queue.routing_key
                 msg = amqp.Message(jsonfy.dumps(message))
                 msg.properties["delivery_mode"] = 2 # persistant
                 c.basic_publish(msg, exchange=exchange_name, routing_key=routing_key)
                 total = total + 1
             except:
                 log.exception('unexpected error')
     return total
예제 #3
0
 def write_json(self, ct, javascript=False):
     self.set_header("Content-Type", "text/javascript; charset=UTF-8")
     self.write(jsonfy.dumps(ct))