67

This two images are from http://zguide.zeromq.org/page:all.

What is the difference between this two pattern if we ignore sink in push-pull pattern ? Is there a difference in how a message gets transfer, if yes what is the difference ?

Community
  • 1
  • 1
Bhuvan
  • 4,028
  • 6
  • 42
  • 84

1 Answers1

87

The difference is that a PUB socket sends the same message to all subscribers, whereas PUSH does a round-robin amongst all its connected PULL sockets.

In your example, if you send just a single message from the root, then all the subscribers will receive it (barring slow subscribers, etc.) but only 1 worker.

The pub/sub pattern is used for wide message distribution according to topics. The push/pull pattern is really a pipelining mechanism. Your push/pull example seems to be attempting to do load-balancing, which is fine, but req/rep might be better suited to that due to other issues.

It looks like the "issues" here are described in the same part of the 0MQ guide you got the image from : push/pull ventilator example

atakli
  • 128
  • 1
  • 9
SteveLove
  • 3,137
  • 15
  • 17
  • 4
    I would also like to know the difference in terms of lost messages...i.e what would happen if server PUB or PUSH a message and client [1] lost connection and reconnect [2] client is connected all the time but client was busy doing work and was not in .recv() – Bhuvan Jul 23 '13 at 16:45
  • 1
    `SUB` and `PULL` sockets have in common the property that they consume from available messages even when the client code isn't doing a `recv`, so in your example, client[2] would get the messages in either case, and client[1] would start getting new messages when it reconnects. Importantly, neither socket type is "addressed" to a particular client. – SteveLove Jul 24 '13 at 09:25
  • 1
    where are you getting this info.... hit and trial with zeroMQ or you found some cool resource ? – Bhuvan Jul 24 '13 at 12:46
  • 1
    A bit of both :) The guide is excellent, and worth reading in detail. – SteveLove Jul 24 '13 at 13:22
  • 1
    Is one better than the other in a N-to-1 scheme, I.E. having multiple publishers (or pushers) sending to a single subscriber (or puller)? – lindhe Nov 20 '17 at 13:28
  • for the new version of zeromq ( >= 3.2.0 ) this is not correct anymore. In the new version, if I understood correctly, the selection of messages is done on PUB side. So messages should now be distrubed like in the PUSH/PULL example. – Dimfred Apr 01 '19 at 13:45