Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZeroMQ: I want Publish–Subscribe to drop older messages in favor of newer ones

I'm using ZeroMQ publish–subscribe sockets to connect two processes. The publishing process is a sensor, and has a much faster refresh rate than the subscription process. I want the subscription process to only use the most recent message in the queue — and ignore older messages altogether.

I've tried setting a highwater mark on the subscriber, but that seems to drop newer messages rather than older.

Is there a publish–subscribe pattern someone can direct me toward for this purpose?

like image 592
Translunar Avatar asked Feb 11 '23 23:02

Translunar


1 Answers

read about the conflate feature from documentation on zeromq (it is kind of new), I think it is exactly what you want.

From the documentation:

ZMQ_CONFLATE: Keep only last message If set, a socket shall keep only one message in its inbound/outbound queue, this message being the last message received/the last message to be sent. Ignores 'ZMQ_RCVHWM' and 'ZMQ_SNDHWM' options. Does not support multi-part messages, in particular, only one part of it is kept in the socket internal queue.

like image 88
somdoron Avatar answered Apr 09 '23 07:04

somdoron