I have a number of nodes that will use a secondary service to be informed about the address of each other. I want to be able to publish information so as all the other nodes can hear it. Using an
XPUB socket is not an option I would want to go with here as I want this system to be distributed.
What I have tried is something that sums up to:
1 Create a
def pub_stream(self): self.pub = self.context.socket(zmq.PUB) self.pub.bind(self.endpoint)
2 Create a
def sub_stream(self): ioloop = IOLoop.instance() socket = self.context.socket(zmq.SUB) self.sub_stream = ZMQStream(socket, ioloop) self.sub_stream.on_recv(self.on_message) self.subs_stream.setsockopt(zmq.SUBSCRIBE, self.topic)
3 At some point receive the addresses of all other nodes and connect to them,
# close and restart sub_stream to get rid of any previous connections for endpoint in endpoints: self.sub_stream.connect(endpoint)
No messages are passed on the
on_message callback though. Is what I am doing correct, if not, what is a better way of doing what I want to achieve?