| 319 | |
| 320 | |
| 321 | class FMQ: |
| 322 | _instance = None |
| 323 | _context = None |
| 324 | |
| 325 | def __new__(cls, config_path="fmq_config.json"): |
| 326 | if cls._instance is None: |
| 327 | cls._instance = super().__new__(cls) |
| 328 | EndpointManager.load_config() |
| 329 | |
| 330 | # Determine IO threads based on global defaults |
| 331 | io_threads = 1 |
| 332 | if EndpointManager.config.endpoints: |
| 333 | # Use max io_threads among all endpoints |
| 334 | io_threads = max(ep.io_threads for ep in EndpointManager.config.endpoints.values()) |
| 335 | |
| 336 | cls._context = zmq.asyncio.Context(io_threads=io_threads) |
| 337 | return cls._instance |
| 338 | |
| 339 | def queue(self, name: str, role="producer") -> Queue: |
| 340 | return Queue(self._context, name, role) |
| 341 | |
| 342 | def topic(self, name: str) -> Topic: |
| 343 | return Topic(self._context, name) |
| 344 | |
| 345 | async def destroy(self): |
| 346 | # Destroy ZeroMQ context |
| 347 | self._context.term() |
no outgoing calls