示例#1
0
文件: queue.py 项目: MiloJiang/kuyruk
 def send(self, obj):
     """Send a single message to the queue.
     obj must be JSON serializable."""
     logger.info('sending to queue: %r message: %r', self.name, obj)
     properties = pika.BasicProperties(
         content_type='application/json',
         delivery_mode=2)
     return self.channel.basic_publish(
         exchange='',
         routing_key=self.name,
         body=Message.encode(obj),
         properties=properties)
示例#2
0
 def receive(self):
     """Get a single message from queue."""
     message = self.channel.basic_get(self.name)
     return Message.decode(message)