I am currently designing a message broker in CZMQ (High-level C binding for ZeroMQ). My broker design is somewhat like the typical star-topology but with additional REP
-sockets to communicate with the publishers and the subscribers. I also have a PUB
-socket to notify publishers about subscribers.
When a node connects to the broker it has to do a handshake through this REP
-socket and that node then gets added to an internal list in the server. My node structure looks like this:
struct node {
int type;
char *uuid;
char *path;
size_t path_len;
int64_t timestamp;
};
The path
variable is the subscription path that the publisher/subscriber is using, e.g. /path/to/subscription
.
I keep two different internal lists, one for publishers and one for subscribers. I want to design it so that when a publisher has no subscriber the server will notify that publisher so it can stop sending out messages until another subscriber that subscribes to that publisher.
The problem I am having is that I don't know how to figure out if a publisher has no subscribers, for example lets say that a publisher publishes to /path/to/data
, I then need to find if there are any subscriber that are subscribed to /path
, /path/to
or /path/to/data
.
Each node in this network has a unique ID, the uuid
. Each publisher has a SUB
-socket that subscribes to it's own uuid
so that it can receive updates from the server.