I'm observing different behaviors between ZMQ PUSH/PULL and PUB/SUB patterns when using ZMQStream. In PUSH/PULL, if my PULL socket starts late, it still receives messages that were sent earlier. However, in PUB/SUB, if the subscriber starts late, it misses all messages sent before it connected.
from zmq.eventloop import ioloop, zmqstreamimport zmqimport time# PUSH/PULL Exampledef push_example(): context = zmq.Context() push_socket = context.socket(zmq.PUSH) push_stream = zmqstream.ZMQStream(push_socket) push_socket.connect("tcp://*:5555") # Messages get queued even if PULL isn't started yet push_stream.send_string("Message 1") # This will be received when PULL startsdef pull_example(): context = zmq.Context() pull_socket = context.socket(zmq.PULL) pull_stream = zmqstream.ZMQStream(pull_socket) pull_socket.bind("tcp://localhost:5555") # Will receive Message 1 even though started late# PUB/SUB Exampledef pub_example(): context = zmq.Context() pub_socket = context.socket(zmq.PUB) pub_stream = zmqstream.ZMQStream(pub_socket) pub_socket.bind("tcp://*:5555") # Message will be lost if SUB isn't already listening pub_stream.send_string("Message 1") # This will be missed by late subscriberdef sub_example(): context = zmq.Context() sub_socket = context.socket(zmq.SUB) sub_stream = zmqstream.ZMQStream(sub_socket) sub_socket.connect("tcp://localhost:5555") sub_socket.setsockopt_string(zmq.SUBSCRIBE, "") # Will NOT receive Message 1 since started late