我想从客户端向服务器发送数据。只有最后一条消息对服务器很重要。如果服务器在失败后恢复,我只希望服务器从客户端获取最后一条消息。
当服务器关闭时,我希望客户端继续处理并发送消息,或者至少将它们放入队列中(一条消息的长度)。
我尝试使用 NetMQ/ZeroMQ 来实现此目的。怎么办?
谢谢!
最佳答案
首先使用 PubSub,其中客户端是发布者,使用 PubSub,您只能在在线时收到消息,如果订阅者(在您的情况下是服务器)宕机,则会错过所有消息(如 radio )
ZeroMQ还有一个名为Conflate的功能(NetMQ还没有,你可能想移植它),看看下面的问题:
ZeroMQ: I want Publish–Subscribe to drop older messages in favor of newer ones
还有来自 ZeroMQ 文档的合并描述:
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 - 如何使用 NetMQ/ZeroMQ 仅发送最后一条消息到服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30392834/