Inside the `/message` enpoint we put a message onto the internal event queue, which gets read by TestAgent. This agent, in turn, logs the message (temporary behaviour until we implement RI integration). The name TestAgent is of course temporary, this is just for exploratory purposes. ref: N25B-165
24 lines
585 B
Python
24 lines
585 B
Python
from fastapi import APIRouter, Request
|
|
import logging
|
|
|
|
from zmq import Socket
|
|
|
|
from control_backend.schemas.message import Message
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/message", status_code=202)
|
|
async def receive_message(message: Message, request: Request):
|
|
logger.info("Received message: %s", message.message)
|
|
|
|
topic = b"message"
|
|
body = message.model_dump_json().encode("utf-8")
|
|
|
|
pub_socket: Socket = request.app.state.internal_comm_socket
|
|
|
|
pub_socket.send_multipart([topic, body])
|
|
|
|
return {"status": "Message received"}
|