Skip to content

🐛 rabbitmq queue name prefix is unique during the lifecycle of the container #6365

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

Merged
merged 15 commits into from
Sep 18, 2024
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/service-library/src/servicelib/rabbitmq/_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import logging
import os
import socket
from typing import Any, Final

import aio_pika
import psutil
from aiormq.exceptions import ChannelPreconditionFailed
from pydantic import NonNegativeInt
from tenacity import retry
Expand Down Expand Up @@ -51,7 +53,13 @@ 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()}"
# NOTE: below prefix is guaranteed to change each time the preocess restarts
# Why is this desiarable?
# 1. the code base makes the above assumption, otherwise subcscribers and consumers do not work
# 2. enables restartability of webserver during [re]deploys
prefix_create_time = f"{psutil.Process(os.getpid()).create_time()}".strip(".")[-6:]

return f"{base_name}_{socket.gethostname()}_{prefix_create_time}"


async def declare_queue(
Expand Down
Loading