Commit a82ae57c authored by Christos Stavrakakis's avatar Christos Stavrakakis

snf-common: Support 'no_ack' in AMQP clients

Enable the Synnefo AMQP clients to consume messages from the queues
without requiring acknowledgments.

Also, add the missing 'exclusive' argument in 'AMQPHaighaClient'.
parent 267ba53d
......@@ -227,7 +227,7 @@ class AMQPHaighaClient():
(exchange, routing_key, body) = self.unacked[mid]
self.basic_publish(exchange, routing_key, body)
def basic_consume(self, queue, callback):
def basic_consume(self, queue, callback, no_ack=False, exclusive=False):
"""Consume from a queue.
@type queue: string or list of strings
......@@ -238,7 +238,8 @@ class AMQPHaighaClient():
self.consumers[queue] = callback, consumer=callback, no_ack=False), consumer=callback, no_ack=no_ack,
def basic_wait(self):
......@@ -254,8 +255,8 @@ class AMQPHaighaClient():
def basic_get(self, queue):, no_ack=False)
def basic_get(self, queue, no_ack=False):, no_ack=no_ack)
def basic_ack(self, message):
......@@ -304,7 +304,7 @@ class AMQPPukaClient(object):
def basic_consume(self, queue, callback, prefetch_count=0):
def basic_consume(self, queue, callback, no_ack=False, prefetch_count=0):
"""Consume from a queue.
@type queue: string or list of strings
......@@ -327,7 +327,8 @@ class AMQPPukaClient(object):
consume_promise = \
return consume_promise
......@@ -347,14 +348,14 @@ class AMQPPukaClient(object):
return self.client.wait(self.consume_promises, timeout)
def basic_get(self, queue):
def basic_get(self, queue, no_ack=False):
"""Get a single message from a queue.
This is a non-blocking method for getting messages from a queue.
It will return None if the queue is empty.
get_promise = self.client.basic_get(queue=queue)
get_promise = self.client.basic_get(queue=queue, no_ack=no_ack)
result = self.client.wait(get_promise)
if 'empty' in result:
# The queue is empty
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment