ZeroMQ PUB/XPUB/XSUB/SUB filtering
Asked Answered
G

1

7

I am trying to determine the exact behaviour and potential limitations of the so-called 'Extended Pub-Sub architecture' from the ØMQ guide.

XPUB and XSUB are described:

We need XPUB and XSUB sockets because ZeroMQ does subscription forwarding from subscribers to publishers. XSUB and XPUB are exactly like SUB and PUB except they expose subscriptions as special messages. The proxy has to forward these subscription messages from subscriber side to publisher side, by reading them from the XSUB socket and writing them to the XPUB socket. This is the main use case for XSUB and XPUB.

I've set up a the XSUB and XPUB sockets as the front-end and back-end of a proxy, and have another pair of PAIR sockets wired into the capture port. This allows me to observe the messages being passed through the proxy.

In my architecture each node is both a PUB and a SUB. Essentially I'm hoping this XPUB/XSUB proxy will provide a shared bus, with topic-prefix subscriptions.

After a SUB node connects, it must subscribe with a (potentially empty) topic. This causes a one-frame message to be transmitted through the proxy. Assuming my topic is {0xff 0xFF}, the message is:

{0x01 0xFF 0xFF}

The leading 0x01 indicates a subscription, followed by the topic bytes. A similar message with a 0x00 instead of a 0x01 represents an unsubscribe.

What I am concerned about is where exactly the subscription information is kept in this architecture.

According to the guide:

From ZeroMQ v3.x, filtering happens at the publisher side when using a connected protocol (tcp:// or ipc://).

If filtering is indeed performed on the publisher side, then is it a problem if a SUB subscribes before a PUB comes online? Will the PUB be informed of pre-existing subscriptions, perhaps from XSUB?

My system will have nodes with dynamic lifetimes. Will this be an issue, and are there any other issues I should be aware of?

Gagliardi answered 19/2, 2015 at 15:13 Comment(0)
S
2

If filtering is indeed performed on the publisher side, then is it a problem if a SUB subscribes before a PUB comes online?

No, that will work itself out.

Will the PUB be informed of pre-existing subscriptions, perhaps from XSUB?

Yes exactly.

My system will have nodes with dynamic lifetimes. Will this be an issue, and are there any other issues I should be aware of?

You'll lose published messages that have no subscribers, so either create a proxy that windows published messages or make subscribers ask publishers to re-publish and have idempotent handling of messages.

Here's a sample of a full-duplex proxy that you can play around with. You'll note that if you start the "pong" (the wall that the ball bounces on) before "ping" (the publisher of the ball), it will all work, but if you publish a ping before the pong subscriber is started, it will be lost.

Stalinism answered 17/2, 2016 at 14:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.