几天前我才开始使用zeromq。我的目标是设计一个具有多个代理(代理网络)的发布订阅系统。我已经阅读了 zeromq 指南的相关部分,并为简单的发布子系统编写了代码。如果有人可以帮助我解决以下问题:
据我所知,代理(xpub-xsub 套接字)也将有推/拉套接字来传递 pub-sub 消息。那是对的吗?如果您在经纪人应如何沟通方面提供任何帮助,我们将不胜感激。经纪人之间是否应该有中介?
任何设计指南都会很有帮助。谢谢。
最佳答案
The guide says that we should use xpub and xsub sockets when dynamic discovery is required. Can someone please explain the difference between the sockets: xpub and pub, and xsub and sub.
XPUB
只是意味着许多发布者,与 PUB
相比,这意味着单个发布者。
XSUB
表示许多订阅者,而 SUB
表示单个订阅者。
如果你想将许多订阅者连接到许多发布者,同时仍然享受动态发现的好处,你需要一个中间代理;如下图所示。 PUB 套接字向代理发送消息; XSUB 将消息转发给 XPUB,然后 XPUB 将这些消息分发给所有监听的 SUB。
创建这样一个代理的代码很简单(如下),PUB 和 SUB 端很简单,查看示例 code .
Socket xsub = ctx.createSocket(ZMQ.XSUB);
input.bind( "tcp://*:5500");
Socket xpub = ctx.createSocket(ZMQ.XPUB);
xpub.bind( "tcp://*:5600");
ZMQ.proxy( xsub, xpub, null);
From what I can conceive, the brokers will also have push/pull sockets to communicate the pub-sub messages. Is that correct? Any help in terms of how the brokers should communicate would be appreciated. Should there be any intermediaries between brokers?
查看 Inter-Broker Routing 的指南例子
关于zeromq - 使用 zeromq 设计具有多个代理的发布订阅系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18240197/