diff --git a/coolamqp/attaches/consumer.py b/coolamqp/attaches/consumer.py index 98da3c0e3326edfac7aa2e87eca23922d37796d3..32085bdfb53955dda7ae34e29f72752b2b4b84d7 100644 --- a/coolamqp/attaches/consumer.py +++ b/coolamqp/attaches/consumer.py @@ -87,8 +87,10 @@ class Consumer(Channeler): :param on_message: callable that will process incoming messages :type on_message: callable(ReceivedMessage instance) :param no_ack: Will this consumer require acknowledges from messages? - :param qos: a tuple of (prefetch size, prefetch window) for this consumer - :type qos: tuple(int, int) or tuple(None, int) + :param qos: a tuple of (prefetch size, prefetch window) for this consumer, or an int (prefetch window only) + If an int is passed, prefetch size will be set to 0 (which means undefined), and this int + will be used for prefetch window + :type qos: tuple(int, int) or tuple(None, int) or int :param cancel_on_failure: Consumer will cancel itself when link goes down :type cancel_on_failure: bool :param future_to_notify: Future to succeed when this consumer goes online for the first time. @@ -119,7 +121,9 @@ class Consumer(Channeler): # if this is not None, then it has an attribute # on_cancel_customer(Consumer instance) if qos is not None: - if qos[0] is None: + if isinstance(qos, int): + qos = 0, qos + elif qos[0] is None: qos = 0, qos[1] # prefetch_size=0=undefined self.qos = qos self.qos_update_sent = False # QoS was not sent to server diff --git a/tests/test_attaches/__init__.py b/tests/test_attaches/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/test_attaches/test_consumer.py b/tests/test_attaches/test_consumer.py new file mode 100644 index 0000000000000000000000000000000000000000..3ddf662d060929b2f61bf543928650b6a69146eb --- /dev/null +++ b/tests/test_attaches/test_consumer.py @@ -0,0 +1,13 @@ +# coding=UTF-8 +from __future__ import print_function, absolute_import, division +import six +import unittest +from coolamqp.attaches import Consumer +from coolamqp.objects import Queue + + +class TestConsumer(unittest.TestCase): + def test_issue_26(self): + """Support for passing qos as int""" + cons = Consumer(Queue('wtf'), lambda msg: None, qos=25) + self.assertEquals(cons.qos, (0, 25))