From 902cca4366e282d6981ac908a1ba03d2406f1d72 Mon Sep 17 00:00:00 2001 From: Jet Li Date: Tue, 5 Nov 2024 05:55:48 +0000 Subject: [PATCH] Fix the rabbitmq communication with notification container --- .../backend/infra/rabbitmq/async_client.py | 4 ++-- sites/notification/deploy/alpha/.env | 1 - .../deploy/common/docker-compose.yaml | 24 +++++++++++++++---- sites/notification/deploy/prod/.env | 1 - 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/apps/notification/backend/infra/rabbitmq/async_client.py b/apps/notification/backend/infra/rabbitmq/async_client.py index 2e4ce72..4b5c929 100644 --- a/apps/notification/backend/infra/rabbitmq/async_client.py +++ b/apps/notification/backend/infra/rabbitmq/async_client.py @@ -17,7 +17,6 @@ class AsyncMQClient: self.process_callable = None self.routing_key = self.channel_name self.module_logger = ModuleLogger(sender_id="AsyncMQClient") - self.connection_url = "amqp://guest:guest@{}:{}/".format(app_settings.RABBITMQ_HOST,app_settings.RABBITMQ_PORT) async def bind(self, max_retries=10, event_loop: AbstractEventLoop = None): retry_count = 0 retry_interval = 1 # Start with a 1-second interval @@ -25,7 +24,8 @@ class AsyncMQClient: while retry_count < max_retries: try: self.connection = await aio_pika.connect_robust( - self.connection_url, + host=app_settings.RABBITMQ_HOST, + port=int(app_settings.RABBITMQ_PORT), loop=event_loop, ) self.channel = await self.connection.channel() diff --git a/sites/notification/deploy/alpha/.env b/sites/notification/deploy/alpha/.env index 5a2a30b..ab0d3d0 100755 --- a/sites/notification/deploy/alpha/.env +++ b/sites/notification/deploy/alpha/.env @@ -1,4 +1,3 @@ -export RABBITMQ_HOST=if030-w2-if-vm.mathmast.com export RABBITMQ_PORT=5672 export FREELEAPS_ENV=alpha diff --git a/sites/notification/deploy/common/docker-compose.yaml b/sites/notification/deploy/common/docker-compose.yaml index c1947e9..c438f21 100755 --- a/sites/notification/deploy/common/docker-compose.yaml +++ b/sites/notification/deploy/common/docker-compose.yaml @@ -1,17 +1,17 @@ services: notification: container_name: $APP_NAME - build: + build: context: ${CODEBASE_ROOT} args: CONTAINER_APP_ROOT: ${CONTAINER_APP_ROOT} - profiles: [prod,alpha,dev] + profiles: [ prod, alpha, dev ] restart: always - environment: + environment: - APP_NAME=${APP_NAME} - SERVICE_API_ACCESS_HOST=${SERVICE_API_ACCESS_HOST} - SERVICE_API_ACCESS_PORT=${SERVICE_API_ACCESS_PORT} - - RABBITMQ_HOST=${RABBITMQ_HOST} + - RABBITMQ_HOST=freeleaps-rabbitmq - RABBITMQ_PORT=${RABBITMQ_PORT} - SYSTEM_USER_ID=${SYSTEM_USER_ID} - SMS_FROM=${SMS_FROM} @@ -36,6 +36,20 @@ services: - type: bind source: $DOCKER_BACKEND_LOG_HOME target: $LOG_BASE_PATH + rabbitmq: + image: rabbitmq:3-management + container_name: "freeleaps-rabbitmq" + ports: + - "5672:5672" # RabbitMQ communication port + - "15672:15672" # RabbitMQ management port + networks: + - devbox_freeleaps2-network + healthcheck: + test: [ "CMD", "rabbitmq-diagnostics", "ping" ] + interval: 30s + retries: 5 + start_period: 10s + timeout: 10s networks: devbox_freeleaps2-network: - external: true \ No newline at end of file + external: true diff --git a/sites/notification/deploy/prod/.env b/sites/notification/deploy/prod/.env index f5bb7b7..c769b1e 100755 --- a/sites/notification/deploy/prod/.env +++ b/sites/notification/deploy/prod/.env @@ -1,3 +1,2 @@ -export RABBITMQ_HOST=if010-w2-if-vm.mathmast.com export RABBITMQ_PORT=5672 export FREELEAPS_ENV=prod