Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make QueueConfigurer aware of DLX so dependency can be established #2

Merged
merged 1 commit into from Apr 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions sparkplug/config/queue.py
Expand Up @@ -45,6 +45,12 @@ def __init__(self, name, **kwargs):
convert(create_args, 'arguments', parse_dict)
self.create_args = create_args

dlx = create_args \
.get('arguments', {}) \
.get('x-dead-letter-exchange', None)
if dlx:
self.depends_on(dlx)

def start(self, channel):
_log.debug("Declaring queue %s (%r)", self.queue, self.create_args)

Expand Down
19 changes: 19 additions & 0 deletions sparkplug/test/test_config/test_queue.py
@@ -1,6 +1,8 @@
from nose.tools import eq_
from mock import Mock, call
from sparkplug.config.queue import QueueConfigurer
from sparkplug.config.exchange import ExchangeConfigurer
from sparkplug.config import calculate_dependencies


def test_queue_configurer_arguments_not_passed():
Expand All @@ -21,3 +23,20 @@ def test_queue_configurer_takes_arguments():
'x-dead-letter-exchange': 'dlx',
'x-ttl': 6000})],
channel.queue_declare.call_args_list)


def test_dead_letter_exchange_should_be_declared_first():
q = QueueConfigurer('q')
dlq = QueueConfigurer(
'dlq',
arguments="""{
"x-dead-letter-exchange": "dlx",
"x-dead-letter-routing-key": "q"}""")
dlx = ExchangeConfigurer('dlx', 'direct')
ordered_deps = calculate_dependencies({
'q': q,
'dlq': dlq,
'dlx': dlx
})
# because dlq needs dlx, dlx should be declared before dlq
assert ordered_deps.index(dlx) < ordered_deps.index(dlq)