Extended PUB/SUB topology https://i.stack.imgur.com/GEgpx.png
我在一个有 1 个中介的用例中有多个发布者和多个订阅者。
在 ZeroMQ 指南中,我了解了如何使用额外的方法来同步 1 个发布者和 1 个订阅者REQ/REP
插座。我尝试为我的用例编写同步代码,但如果我尝试根据 1-1 给出的逻辑编写代码,它会变得混乱PUB/SUB
.
当我们只有 1 个发布者时,发布者代码是:
//Socket to receive sync request
zmq::socket_t syncservice (context, ZMQ_REP);
syncservice.bind("tcp://*:5562");
// Get synchronization from subscribers
int subscribers = 0;
while (subscribers < SUBSCRIBERS_EXPECTED) {
// - wait for synchronization request
s_recv (syncservice);
// - send synchronization reply
s_send (syncservice, "");
subscribers++;
}
当我们只有 1 个订阅者时,订阅者代码是:
zmq::socket_t syncclient (context, ZMQ_REQ);
syncclient.connect("tcp://localhost:5562");
// - send a synchronization request
s_send (syncclient, "");
// - wait for synchronization reply
s_recv (syncclient);
现在,当我有多个订阅者时,每个订阅者是否需要向每个发布者发送请求?
我的用例中的发布商来来去去。他们的数量并不固定。
因此,订阅者不会知道要连接到多少个节点以及哪些发布者存在或不存在。
请建议同步扩展的逻辑PUB/SUB
code
鉴于XPUB/XSUB
存在中介节点,
实际上PUB
- 节点发现可能完全毫不费力XSUB
-mediator-side(实际上主要是避免这样的)。
只需使用reversed the XSUB.bind()
-s / PUB.connect()
-s,问题就不再存在了。
很聪明,不是吗?
PUB
-nodes may come and go, yet the XSUB
-side of the Policy-mediator node need not bother ( except for a few initial .setsockopt( { LINGER, IMMEDIATE, CONFLATE, RCVHWM, MAXSIZE } )
performance tuning and robustness increasing settings ), enjoying the still valid and working composition of the actual Topic-filter(s) .setsockopt( zmq.SUBSCRIBE, ** )
settings in-service and may centrally maintain such composition remaining principally agnostic about the state/dynamic of the semi-temporal group of the now / later .connect()
-ed live / dysfunctional PUB
-side Agent-nodes.
更好,不是吗?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)