class ZmqServer: def start(self, port): self._server = Server(port=port) self.pubs = {} def send(self, obj, topic): if not topic in self.pubs: self.pubs[topic] = self._server.pub(topic=topic, embed_topic=True) self.pubs[topic](obj)
def get_server( port: int, topics: List[str]) -> Dict[str, Callable[[BaseMessageType], None]]: # And assigns a callable to publish messages with the topics' srv = Server(port=port) mapping = { topic: srv.pub(topic=topic.encode('utf-8'), embed_topic=True) for topic in topics } return { k: (lambda packet: v(packet.json().encode('utf-8'))) for k, v in mapping.items() }