101 lines
3.5 KiB
Python
101 lines
3.5 KiB
Python
"""
|
|
Punto de entrada principal para VoxPopuli Microservices
|
|
Ejecuta tres APIs en paralelo: Usuarios (puerto 8000), Reportes (puerto 8001) y Notificaciones (puerto 8002)
|
|
"""
|
|
from infrastructure.api.users.app import create_app as create_users_app
|
|
from infrastructure.api.reports.app import create_app as create_reports_app
|
|
from infrastructure.api.notifications.app import create_app as create_notifications_app
|
|
from consumers.report_consumer import ReportConsumer
|
|
from consumers.user_consumer import UserConsumer
|
|
from consumers.notification_consumer import NotificationConsumer
|
|
from core.config import ConfSettings
|
|
import threading
|
|
import uvicorn
|
|
|
|
def run_users_api():
|
|
"""Ejecuta la API de Usuarios en puerto 8000"""
|
|
app_users = create_users_app()
|
|
uvicorn.run(
|
|
app_users,
|
|
host=ConfSettings.host,
|
|
port=8000,
|
|
reload=False,
|
|
log_level=ConfSettings.log_level,
|
|
)
|
|
|
|
def run_reports_api():
|
|
"""Ejecuta la API de Reportes en puerto 8001"""
|
|
app_reports = create_reports_app()
|
|
uvicorn.run(
|
|
app_reports,
|
|
host=ConfSettings.host,
|
|
port=8001,
|
|
reload=False,
|
|
log_level=ConfSettings.log_level,
|
|
)
|
|
|
|
def run_notifications_api():
|
|
"""Ejecuta la API de Notificaciones en puerto 8002"""
|
|
app_notifications = create_notifications_app()
|
|
uvicorn.run(
|
|
app_notifications,
|
|
host=ConfSettings.host,
|
|
port=8002,
|
|
reload=False,
|
|
log_level=ConfSettings.log_level,
|
|
)
|
|
|
|
def run_user_consumer():
|
|
consumer = UserConsumer()
|
|
consumer.start()
|
|
|
|
def run_reports_consumer():
|
|
consumer = ReportConsumer()
|
|
consumer.start()
|
|
|
|
def run_notifications_consumer():
|
|
consumer = NotificationConsumer()
|
|
consumer.start()
|
|
|
|
|
|
def run():
|
|
"""Inicia ambas APIs en threads separados"""
|
|
print("=" * 60)
|
|
print("Iniciando VoxPopuli Microservices...")
|
|
print("=" * 60)
|
|
|
|
users_thread = threading.Thread(target=run_users_api, daemon=True, name="Users-API")
|
|
reports_thread = threading.Thread(target=run_reports_api, daemon=True, name="Reports-API")
|
|
notifications_thread = threading.Thread(target=run_notifications_api, daemon=True, name="Notifications-API")
|
|
user_consumer_thread = threading.Thread(target=run_user_consumer, daemon=True, name="Users-Consumer")
|
|
report_consumer_thread = threading.Thread(target=run_reports_consumer, daemon=True, name="Reports-Consumer")
|
|
notifications_consumer_thread = threading.Thread(target=run_notifications_consumer, daemon=True, name="Notifications-Consumer")
|
|
|
|
|
|
users_thread.start()
|
|
reports_thread.start()
|
|
notifications_thread.start()
|
|
user_consumer_thread.start()
|
|
report_consumer_thread.start()
|
|
notifications_consumer_thread.start()
|
|
|
|
print("\n✓ API de Usuarios ejecutándose en http://0.0.0.0:8000")
|
|
print("✓ API de Reportes ejecutándose en http://0.0.0.0:8001")
|
|
print("✓ API de Notificaciones ejecutándose en http://0.0.0.0:8002")
|
|
print("\nDocumentación disponible en:")
|
|
print(" - Usuarios: http://localhost:8000/docs")
|
|
print(" - Reportes: http://localhost:8001/docs")
|
|
print(" - Notificaciones: http://localhost:8002/docs")
|
|
print("\n" + "=" * 60 + "\n")
|
|
|
|
try:
|
|
users_thread.join()
|
|
reports_thread.join()
|
|
notifications_thread.join()
|
|
except KeyboardInterrupt:
|
|
print("\n\nRecibiendo señal de salida...")
|
|
print("Cerrando APIs...")
|
|
|
|
if __name__ == "__main__":
|
|
run()
|
|
# |