Files
bakery-ia/services/data/app/services/messaging.py
2025-07-18 14:18:52 +02:00

43 lines
1.5 KiB
Python

# ================================================================
# services/data/app/services/messaging.py
# ================================================================
from shared.messaging.rabbitmq import RabbitMQClient
from app.core.config import settings
import logging
logger = logging.getLogger(__name__)
# Single global instance
data_publisher = RabbitMQClient(settings.RABBITMQ_URL, "data-service")
async def setup_messaging():
"""Initialize messaging for data service"""
success = await data_publisher.connect()
if success:
logger.info("Data service messaging initialized")
else:
logger.warning("Data service messaging failed to initialize")
async def cleanup_messaging():
"""Cleanup messaging for data service"""
await data_publisher.disconnect()
logger.info("Data service messaging cleaned up")
# Convenience functions for data-specific events
async def publish_data_imported(data: dict) -> bool:
"""Publish data imported event"""
return await data_publisher.publish_data_event("imported", data)
async def publish_weather_updated(data: dict) -> bool:
"""Publish weather updated event"""
return await data_publisher.publish_data_event("weather.updated", data)
async def publish_traffic_updated(data: dict) -> bool:
"""Publish traffic updated event"""
return await data_publisher.publish_data_event("traffic.updated", data)
async def publish_sales_created(data: dict) -> bool:
"""Publish sales created event"""
return await data_publisher.publish_data_event("sales.created", data)