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)
def receive(self): """Get a single message from queue.""" message = self.channel.basic_get(self.name) return Message.decode(message)