77 lines
2.4 KiB
Python
77 lines
2.4 KiB
Python
"""
|
|
Punto de entrada principal para VoxPopuli Microservices
|
|
Ejecuta dos APIs en paralelo: Usuarios (puerto 8000) y Reportes (puerto 8001)
|
|
"""
|
|
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 consumers.report_consumer import ReportConsumer
|
|
from consumers.user_consumer import UserConsumer
|
|
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_user_consumer():
|
|
consumer = UserConsumer()
|
|
consumer.start()
|
|
|
|
def run_reports_consumer():
|
|
consumer = ReportConsumer()
|
|
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")
|
|
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")
|
|
|
|
|
|
users_thread.start()
|
|
reports_thread.start()
|
|
user_consumer_thread.start()
|
|
report_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("\nDocumentación disponible en:")
|
|
print(" - Usuarios: http://localhost:8000/docs")
|
|
print(" - Reportes: http://localhost:8001/docs")
|
|
print("\n" + "=" * 60 + "\n")
|
|
|
|
try:
|
|
users_thread.join()
|
|
reports_thread.join()
|
|
except KeyboardInterrupt:
|
|
print("\n\nRecibiendo señal de salida...")
|
|
print("Cerrando APIs...")
|
|
|
|
if __name__ == "__main__":
|
|
run()
|
|
# |