Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zeromq which socket should bind on PubSub pattern

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.

like image 569
mmarques Avatar asked Apr 20 '15 15:04

mmarques


People also ask

Does ZeroMQ use sockets?

ZeroMQ patterns are implemented by pairs of sockets with matching types. The built-in core ZeroMQ patterns are: Request-reply, which connects a set of clients to a set of services. This is a remote procedure call and task distribution pattern.

What is a pub socket?

PUB) socket. Data is published along with a topic. The subscribers usually sets a filter on these topics for topic of their interests. while True: topic = random. randrange(9999,10005) messagedata = random.

Is ZeroMQ asynchronous?

ZeroMQ is an asynchronous network messaging library known for its high performance. It's intended use is for distributed systems as well as concurrent systems. In summary, ZMQ allows you to send messages (binary data, serialized data, simple strings, etc.)

What is ZeroMQ context?

A ØMQ context is thread safe and may be shared among as many application threads as necessary, without any additional locking required on the part of the caller. Individual ØMQ sockets are not thread safe except in the case where full memory barriers are issued when migrating a socket from one thread to another.


1 Answers

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.

like image 81
Jason Avatar answered Nov 04 '22 18:11

Jason