refactor: ZMQ context and proxy
Use ZMQ's global context instance and setup an XPUB/XSUB proxy intermediary to allow for easier multi-pubs. close: N25B-217
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import logging
|
||||
|
||||
import zmq
|
||||
from fastapi import APIRouter, Request
|
||||
from zmq import Socket
|
||||
from zmq.asyncio import Context
|
||||
|
||||
from control_backend.core.config import settings
|
||||
from control_backend.schemas.message import Message
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -17,8 +19,8 @@ async def receive_message(message: Message, request: Request):
|
||||
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])
|
||||
pub_socket = Context.instance().socket(zmq.PUB)
|
||||
pub_socket.bind(settings.zmq_settings.internal_pub_address)
|
||||
await pub_socket.send_multipart([topic, body])
|
||||
|
||||
return {"status": "Message received"}
|
||||
|
||||
Reference in New Issue
Block a user