Search code examples
zeromqpublish-subscribe

What can an XSUB-XPUB broker do than a SUB-PUB broker can't?


According to the 0MQ guide, an XSUB-XPUB broker can access the (otherwise hidden) messages related to topic subscriptions by consumers in this scenario:

 many publishers (UP) ---> XSUB|broker|XPUB ---> many subscribers (DOWN)

( publications --> )
( <-- topic subscriptions )

But, if topic filtering is not needed (all messages sent to all recipients), then, the SUB-PUB sockets may be used for the broker:

many publishers ---> SUB|broker|PUB ---> many subscribers
  1. Is this right?

Anyway. Suppose that XSUB-XPUB sockets are used. XSUB publications are forwarded down to XPUB (just as in the SUB-PUB broker version) to reach the consumers.

But now, in the XSUB-XPUB broker version you can listen to "upward topic subscriptions" messages (You can't do that with a SUB-PUB broker).

  1. Here, if you don't want the broker to manage subscriptions. Is it necessary to forward message subscriptions from the X-PUB up to the X-SUB? I guess that subscriptions are effectively handled at the X-PUB socket on the broker (not at the PUB socket of publishers, as consumers are not directly connected to producers). If so, the answer is no. Even, no need to listen for topic subscriptions on the X-PUB. Right?

Thanks


Solution

  • After making a proof of concept program.

    Answer to 1). Yes it is right. At the broker, remember to do

    
    subSocket.bind( "tcp://*:5001" ) // publishers connect to broker endpoint
    subSocket.subscribe( "" ) 
    
    

    in order to get in all messages from all publishers.

    Answer to 2) Subscription filtering is effectively done by XPUB and PUB sockets.

    The reason for using a XSUB-XPUB socket pair is to forward topic subscriptions (coming into the proxy from XPUB) up to the publishers (through XSUB), so the broker only gets messages for topics of interest to any of its subscribers.

    Hence, by using a XSUB-XPUB proxy versus a SUB-PUB proxy, you save messages from publishers to the proxy. In both cases, the traffic from proxy to subscribers is the same.

    Because the code of a XSUB-XPUB proxy is trivial, there is not reason not to use this combination.