Internal Notifier API
A FastAPI-based internal service that receives notification requests and forwards them to RabbitMQ for asynchronous processing and delivery to end users.
Features
- RabbitMQ Integration: Asynchronous message queuing for reliable notification delivery
- Internal API Key Authentication: Secure service-to-service communication
- MySQL Connection Pooling: Database connection management with automatic health checks
- Prometheus Metrics: Built-in request monitoring and tracking
Architecture
This service acts as a gateway between internal services and the notification delivery system:
Internal Services → Internal Notifier API → RabbitMQ → Notification Workers → End Users
Prerequisites
- Python 3.8+
- MySQL database
- RabbitMQ server
- Required Python packages (see Installation)
Installation
pip install -r requirements.txt
Running the Application
python main.py
This starts two servers:
- Main API:
http://0.0.0.0:8101 - Metrics Server:
http://0.0.0.0:9000
API Endpoints
Receive Notifications
POST /internal/receive-notifications
Receives notification data from internal services and queues it to RabbitMQ for delivery.
Headers:
X-API-Key-Internal: Your internal API key
Request Body:
{
"receipent_user_id": 12345,
"message": {
"title": "New Message",
"body": "You have a new notification",
"data": {
"category": "utility",
"link": "https://example.com",
"timestamp": "1760734800"
}
}
}
category- Optional.link- Optional.timestamp- Optional.
Response:
{
"status": "queued"
}
Success: Returns 200 status code when message is successfully queued to RabbitMQ
Error Responses
403 Forbidden: Invalid, missing, or inactive API key500 Internal Server Error: Database, RabbitMQ, or server error
Monitoring
Prometheus Metrics
Prometheus metrics are exposed on port 9000 and include:
- HTTP request counters by method, path, and status code
- Custom metrics from the metrics server
Access metrics at: http://0.0.0.0:9000/metrics
Description
Languages
Python
96.1%
Dockerfile
3.9%