mirror of https://github.com/celery/kombu.git
Added passive option for Exchange
This commit is contained in:
parent
81094e47ff
commit
2d075adba1
|
@ -123,6 +123,7 @@ class Exchange(MaybeChannelBound):
|
|||
type = 'direct'
|
||||
durable = True
|
||||
auto_delete = False
|
||||
passive = False
|
||||
delivery_mode = PERSISTENT_DELIVERY_MODE
|
||||
|
||||
attrs = (
|
||||
|
@ -134,16 +135,17 @@ class Exchange(MaybeChannelBound):
|
|||
('delivery_mode', lambda m: DELIVERY_MODES.get(m) or m),
|
||||
)
|
||||
|
||||
def __init__(self, name='', type='', channel=None, **kwargs):
|
||||
def __init__(self, name='', type='', channel=None, passive=None, **kwargs):
|
||||
super(Exchange, self).__init__(**kwargs)
|
||||
self.name = name or self.name
|
||||
self.type = type or self.type
|
||||
self.passive = passive or self.passive
|
||||
self.maybe_bind(channel)
|
||||
|
||||
def __hash__(self):
|
||||
return hash('E|%s' % (self.name, ))
|
||||
|
||||
def declare(self, nowait=False, passive=False):
|
||||
def declare(self, nowait=False):
|
||||
"""Declare the exchange.
|
||||
|
||||
Creates the exchange on the broker.
|
||||
|
@ -156,7 +158,7 @@ class Exchange(MaybeChannelBound):
|
|||
return self.channel.exchange_declare(
|
||||
exchange=self.name, type=self.type, durable=self.durable,
|
||||
auto_delete=self.auto_delete, arguments=self.arguments,
|
||||
nowait=nowait, passive=passive,
|
||||
nowait=nowait, passive=self.passive,
|
||||
)
|
||||
|
||||
def bind_to(self, exchange='', routing_key='',
|
||||
|
|
|
@ -16,7 +16,6 @@ from .utils import Mock
|
|||
def get_conn():
|
||||
return Connection(transport=Transport)
|
||||
|
||||
|
||||
class test_binding(TestCase):
|
||||
|
||||
def test_constructor(self):
|
||||
|
@ -130,6 +129,10 @@ class test_Exchange(TestCase):
|
|||
exc = Exchange('foo', 'direct', delivery_mode='transient')
|
||||
self.assertEqual(exc.delivery_mode, Exchange.TRANSIENT_DELIVERY_MODE)
|
||||
|
||||
def test_set_passive_mode(self):
|
||||
exc = Exchange('foo', 'direct', passive=True)
|
||||
self.assertTrue(exc.passive)
|
||||
|
||||
def test_set_persistent_delivery_mode(self):
|
||||
exc = Exchange('foo', 'direct', delivery_mode='persistent')
|
||||
self.assertEqual(exc.delivery_mode, Exchange.PERSISTENT_DELIVERY_MODE)
|
||||
|
|
Loading…
Reference in New Issue