maybe_declare should not cache declaration if entity is not durable

This commit is contained in:
Ask Solem 2012-01-05 16:32:44 +00:00
parent 4c599f9719
commit 2578e442f0
3 changed files with 11 additions and 1 deletions

View File

@ -46,6 +46,9 @@ class MaybeChannelBound(Object):
_channel = None
_is_bound = False
#: Defines whether maybe_declare can skip declaring this entity twice.
can_cache_declaration = False
def __call__(self, channel):
"""`self(channel) -> self.bind(channel)`"""
return self.bind(channel)

View File

@ -20,7 +20,7 @@ def maybe_declare(entity, channel):
declared = declared_entities[channel.connection.client]
if not entity.is_bound:
entity = entity(channel)
if entity not in declared:
if not entity.can_cache_declaration or entity not in declared:
entity.declare()
declared.add(entity)
return True

View File

@ -236,6 +236,9 @@ class Exchange(MaybeChannelBound):
def __repr__(self):
return super(Exchange, self).__repr__("Exchange %s(%s)" % (self.name,
self.type))
@property
def can_cache_declaration(self):
return self.durable
class Queue(MaybeChannelBound):
@ -512,3 +515,7 @@ class Queue(MaybeChannelBound):
"Queue %s -> %s -> %s" % (self.name,
self.exchange,
self.routing_key))
@property
def can_cache_declaration(self):
return self.durable