Skip to content

Commit

Permalink
SQS transport now replaces dots in queue names with dashes
Browse files Browse the repository at this point in the history
and also all other punctuation with underscores, as SQS only
accepts alphanumerics + -,_.

Thanks to adamn
  • Loading branch information
ask committed May 25, 2011
1 parent 3ec1258 commit 6bcedcb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion funtests/tests/test_SQS.py
Expand Up @@ -8,9 +8,10 @@
class test_SQS(transport.TransportCase):
transport = "SQS"
prefix = "sqs"
sep = "-" # SQS queue names cannot include '.'
event_loop_max = 100
message_size_limit = 4192 # SQS max body size / 2.
suppress_disorder_warning = True # does not guarantee FIFO order,
# even in simple cases.

def before_connect(self):
if "AWS_ACCESS_KEY_ID" not in os.environ:
Expand Down
3 changes: 2 additions & 1 deletion funtests/transport.py
Expand Up @@ -61,6 +61,7 @@ class TransportCase(unittest.TestCase):
password = None
event_loop_max = 100
connection_options = {}
suppress_disorder_warning = False

connected = False
skip_test_reason = None
Expand Down Expand Up @@ -152,7 +153,7 @@ def test_produce__consume_large_messages(self, bytes=1048576, n=10,
for msg in consumeN(self.connection, consumer, n)]
self.assertEqual(len(received), n)
ordering = [i for i, _ in received]
if ordering != range(n):
if ordering != range(n) and not self.suppress_disorder_warning:
warnings.warn(
"%s did not deliver messages in FIFO order: %r" % (
self.transport, ordering))
Expand Down
16 changes: 15 additions & 1 deletion kombu/transport/SQS.py
Expand Up @@ -10,6 +10,7 @@
"""
import socket
import string

from Queue import Empty

Expand All @@ -22,11 +23,24 @@
from kombu.utils import cached_property


# dots are replaced by dash, all other punctuation
# replaced by underscore.
CHARS_REPLACE = string.punctuation.replace('-', '') \
.replace('_', '') \
.replace('.', '')
CHARS_REPLACE_TABLE = string.maketrans(CHARS_REPLACE + '.',
"_" * len(CHARS_REPLACE) + '-')


class Channel(virtual.Channel):
_client = None

def entity_name(self, name, table=CHARS_REPLACE_TABLE):
return name.translate(table)

def _new_queue(self, queue, **kwargs):
return self.client.create_queue(queue, self.visibility_timeout)
return self.client.create_queue(self.entity_name(queue),
self.visibility_timeout)

def _get(self, queue):
q = self._new_queue(queue)
Expand Down

0 comments on commit 6bcedcb

Please sign in to comment.