I'm using pyzmq
library with pub/sub pattern. I have some fast ZMQ publishers using .connect()
method and a slower ZMQ subscriber using .bind()
method.
Then after a few minutes, my subscriber receives the old data published from the publisher — due to ZMQ buffer.
My Question:
Is there any approach to manage ZMQ queue buffer size? (set a limited buffer)
[NOTE]:
- I don't want to use ZMQ PUSH/PULL.
- I've read this post, but this approach clear buffer only: clear ZMQ buffer
- I also tried with
high watermark
options, but it didn't work:
socket.setsockopt(zmq.RCVHWM, 10) # not working socket.setsockopt(zmq.SNDHWM, 10) # not working
Publisher:
import zmq
import time
port = "5556"
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:%s" % port)
socket.setsockopt(zmq.SNDHWM, 10) # not working
while True:
data = time.time()
print("%d" % data)
socket.send("%d" % data)
time.sleep(1)
Subscriber:
import zmq
import time
port = "5556"
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect("tcp://localhost:%s" % port)
socket.setsockopt(zmq.SUBSCRIBE, '')
socket.setsockopt(zmq.RCVHWM, 10) # not working
while 1:
time.sleep(2) # A speed reducer like.
data = socket.recv()
print(data)
The queue size is still more than 10 despite these options (via configured send/receive high watermark
).