-
Notifications
You must be signed in to change notification settings - Fork 32
🐛 fix rabbit mq unique queue name #6328
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| import logging | ||
| import random | ||
| import socket | ||
| import string | ||
| from typing import Any, Final | ||
|
|
||
| import aio_pika | ||
|
|
@@ -19,6 +21,9 @@ | |
|
|
||
| RABBIT_QUEUE_MESSAGE_DEFAULT_TTL_MS: Final[int] = 15 * _MINUTE * 1000 | ||
|
|
||
| CHARACTERS = string.ascii_letters + string.digits | ||
| _GENERATE_RANDOM_STRING_LENGTH = 6 | ||
|
|
||
|
|
||
| class RabbitMQRetryPolicyUponInitialization: | ||
| """Retry policy upon service initialization""" | ||
|
|
@@ -51,7 +56,10 @@ async def wait_till_rabbitmq_responsive(url: str) -> bool: | |
|
|
||
|
|
||
| def get_rabbitmq_client_unique_name(base_name: str) -> str: | ||
| return f"{base_name}_{socket.gethostname()}" | ||
| random_string = "".join( | ||
| random.choice(CHARACTERS) for _ in range(_GENERATE_RANDOM_STRING_LENGTH) | ||
| ) | ||
| return f"{base_name}_{socket.gethostname()}_{random_string}" | ||
matusdrobuliak66 marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not convinced by this. The whole idea of using the hostname here was to make it unique. I would rather drop the hostname and use a larger random string, which makes collisions less likely. You might even get away with using a uuid from which you strip the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please note that all your tests will fail if something fishy is happening with the queue names. You might want to check what your change introduced. |
||
|
|
||
|
|
||
| async def declare_queue( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pcrespov I guess I can create a function for this and add it to
utils_secrets.py? we do not yet have one that combines letters and numbers as far as I can see.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess here
generate_passcodemight work for this case as well.In any case, more than a secure here the idea is to generate some sort of unique identifer.
I would start a new module with helpesr like
servicelib.identifiers_utilsand add functions that can produce unique identifiers e.g. based on some unique feature (time, hostname, etc...)NOTE that the value you pass to
input_stringprovides the "uniqueness" scope of that value. Therefore you use as discriminator.