From a777752e172e7967c4e18d03e32d4efa8b53f17e Mon Sep 17 00:00:00 2001 From: A'zamov Samandar Date: Mon, 21 Apr 2025 20:06:20 +0500 Subject: [PATCH] Yangi notification model va RabbitMQ ulanish funksiyalari qo'shildi --- notification/internal/models/fcm.go | 1 + order/core/utils/notification.py | 21 +++++++++++++++++++++ order/core/utils/rabbitmq.py | 15 +++++++++++++++ user/config/conf/cache.py | 1 - 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 notification/internal/models/fcm.go create mode 100644 order/core/utils/notification.py create mode 100644 order/core/utils/rabbitmq.py diff --git a/notification/internal/models/fcm.go b/notification/internal/models/fcm.go new file mode 100644 index 0000000..2640e7f --- /dev/null +++ b/notification/internal/models/fcm.go @@ -0,0 +1 @@ +package models diff --git a/order/core/utils/notification.py b/order/core/utils/notification.py new file mode 100644 index 0000000..5a84500 --- /dev/null +++ b/order/core/utils/notification.py @@ -0,0 +1,21 @@ +# rabbitmq.py + +from kombu import Exchange, Producer +from .rabbitmq import get_connection + +_channel = None +_exchange = Exchange('notification', type='direct') +_producer = None + +def get_producer(): + global _producer, _channel + if _producer is None: + conn = get_connection() + _channel = conn.channel() + _producer = Producer(_channel, exchange=_exchange, routing_key="notification") + return _producer + + +def send_notification(message: dict): + producer = get_producer() + producer.publish(message, serializer='json') diff --git a/order/core/utils/rabbitmq.py b/order/core/utils/rabbitmq.py new file mode 100644 index 0000000..890dbc5 --- /dev/null +++ b/order/core/utils/rabbitmq.py @@ -0,0 +1,15 @@ +# rabbitmq.py + +from kombu import Connection + +rabbit_url = 'amqp://guest:guest@rabbitmq:5672/' +_connection = None + + +def get_connection(): + global _connection + if _connection is None or not _connection.connected: + _connection = Connection(rabbit_url) + _connection.ensure_connection(max_retries=3) + return _connection + diff --git a/user/config/conf/cache.py b/user/config/conf/cache.py index cd724b5..95371c9 100644 --- a/user/config/conf/cache.py +++ b/user/config/conf/cache.py @@ -10,7 +10,6 @@ CACHES = { CACHE_MIDDLEWARE_SECONDS = env("CACHE_TIMEOUT") - CACHEOPS_REDIS = env.str("REDIS_URL") CACHEOPS_DEFAULTS = { "timeout": env.str("CACHE_TIMEOUT"),