Zeromq which socket should bind on PubSub pattern

浪尽此生 提交于 2019-12-10 13:19:57

问题


I have been reading about ZeroMQ more specifically about NetMQ and almost every Pub/Sub examples I saw used to Bind the Publisher socket and then the Subscriber socket connects to the other.

So i'm wondering if it is possible to do the reverse, i mean Bind the Subscriber socket and then publishers connect to it.

Is this possible ? (I didn't found anything clear on documentation) What are the disadvantages using this connection strategy ?

Any help will be usefull.


回答1:


Yes, you can reverse it and there are no disadvantages to using that connection strategy... provided it suits your purpose.

In ZMQ, the driving concept behind "binding" and "connecting" is that one side is often considered to be more reliable (and usually there will be fewer nodes), and the other side is considered to be more transient (and there could be more numerous nodes). The reliable side would be considered your "server", and you should bind() on that side, the transient side would be considered your "client" (or clients), and you should connect() on that side.

Typically, we think of a stable "server" publishing information constantly, to many "client" subscribers which may come and go. This is represented in the examples that you see: bind on pub, connect on sub.

But, you could just as easily have a stable "server" subscribing to any output from many "client" publishers that connect to it, accepting any information that they're sending while they are available. Bind on sub, connect on pub.

You're not limited to one server, either, it's just the simplest example - however, you're more limited if you're running all of your sockets on the same computer. Binding on the same address with more than one socket will produce a conflict, but you can connect as many sockets to the same address as you like.

In many cases, both sides of the communication are really intended to be reliable and long running, in which case it's useful to think of the node which sends the information as the server, and the one which receives it as the client. In which case, we're back to bind on pub, connect on sub.



来源:https://stackoverflow.com/questions/29752338/zeromq-which-socket-should-bind-on-pubsub-pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!