ZeroMQ:我希望发布-订阅删除旧消息以支持新消息 [英] ZeroMQ: I want Publish–Subscribe to drop older messages in favor of newer ones
问题描述
我使用 ZeroMQ 发布订阅套接字来连接两个进程.发布过程是一个传感器,刷新率比订阅过程快得多.我希望订阅过程只使用队列中的最新消息,而完全忽略旧消息.
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?
推荐答案
从 zeromq 文档(有点新),我认为这正是您想要的.
read about the conflate feature from documentation on zeromq (it is kind of new), I think it is exactly what you want.
来自文档:
ZMQ_CONFLATE:只保留最后一条消息如果设置,套接字应只保留入站/出站队列中的一条消息,该消息是最后一条收到的消息/要发送的最后一条消息.忽略ZMQ_RCVHWM"和'ZMQ_SNDHWM' 选项.不支持多部分消息,在特别是,只有一部分保留在套接字内部队列中.
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.
这篇关于ZeroMQ:我希望发布-订阅删除旧消息以支持新消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!