summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Niedziela-Brach <niedziela.brach@gmail.com>2021-04-04 17:02:03 +0200
committerGitHub <noreply@github.com>2021-04-04 18:02:03 +0300
commit44dcc33a74bfb497ace1071d9d4b9851fa04f561 (patch)
treeaf829a61d52e918d8c90c56d3b9f624f57ded62a
parent78cc97b549e3b58005747ecb3d160f2b60ba63ba (diff)
downloadkombu-44dcc33a74bfb497ace1071d9d4b9851fa04f561.tar.gz
Azure Service Bus - versatile queue names fix (#1324)
* fixed character replace table according to the comment above - dots replaced by dashes, other punctuations replaced by underscores * optimised with precalculated punctuation set - according to @thedrow suggestion * queue name tests * cleanup
-rw-r--r--kombu/transport/azureservicebus.py4
-rw-r--r--t/unit/transport/test_azureservicebus.py25
2 files changed, 28 insertions, 1 deletions
diff --git a/kombu/transport/azureservicebus.py b/kombu/transport/azureservicebus.py
index 74a5cd17..331d0038 100644
--- a/kombu/transport/azureservicebus.py
+++ b/kombu/transport/azureservicebus.py
@@ -66,8 +66,10 @@ from azure.servicebus.management import ServiceBusAdministrationClient
from . import virtual
# dots are replaced by dash, all other punctuation replaced by underscore.
+PUNCTUATIONS_TO_REPLACE = set(string.punctuation) - {'_', '.', '-'}
CHARS_REPLACE_TABLE = {
- ord(c): 0x5f for c in string.punctuation if c not in '_'
+ ord('.'): ord('-'),
+ **{ord(c): ord('_') for c in PUNCTUATIONS_TO_REPLACE}
}
diff --git a/t/unit/transport/test_azureservicebus.py b/t/unit/transport/test_azureservicebus.py
index 909592ec..329eeac7 100644
--- a/t/unit/transport/test_azureservicebus.py
+++ b/t/unit/transport/test_azureservicebus.py
@@ -275,3 +275,28 @@ def test_purge(mock_queue: MockQueue):
size = mock_queue.channel._size(mock_queue.queue_name)
assert size == 0
assert len(mock_queue.asb.queues[mock_queue.queue_name].waiting_ack) == 0
+
+
+def test_custom_queue_name_prefix():
+ conn = Connection(
+ URL_CREDS,
+ transport=azureservicebus.Transport,
+ transport_options={'queue_name_prefix': 'test-queue'}
+ )
+ channel = conn.channel()
+
+ assert channel.queue_name_prefix == 'test-queue'
+
+
+def test_custom_entity_name():
+ conn = Connection(URL_CREDS, transport=azureservicebus.Transport)
+ channel = conn.channel()
+
+ # dashes allowed and dots replaced by dashes
+ assert channel.entity_name('test-celery') == 'test-celery'
+ assert channel.entity_name('test.celery') == 'test-celery'
+
+ # all other punctuations replaced by underscores
+ assert channel.entity_name('test_celery') == 'test_celery'
+ assert channel.entity_name('test:celery') == 'test_celery'
+ assert channel.entity_name('test+celery') == 'test_celery'