I\'m using pyzmq
library with pub/sub pattern. I have some quick ZMQ publisher by .connect()
method and a
To set the queue/buffer size you need to set the high water marks via the socket options
setsockopt(zmq.SNDHWM, 10)
setsockopt(zmq.RCVHWM, 10)
I found a way to get "Last message only" option in ZMQ
Subscribe socket (using CONFLATE
option).
But first you should set the CONFLATE
option before you connect:
import zmq
import time
port = "5556"
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.setsockopt(zmq.SUBSCRIBE, '')
socket.setsockopt(zmq.CONFLATE, 1) # last msg only.
socket.connect("tcp://localhost:%s" % port) # must be placed after above options.
while 1:
time.sleep(2) # Dummy delay
data = socket.recv()
print(data)
On the other word, I removed any buffered queue in subscriber code.
[NOTE]:
In addition, with the zmq.SNDBUF
and zmq.RCVBUF
options we could set a limit on ZMQ buffer size. (More complete and an example)