Using ZMQ Proxy in a many-to-one relationship

Viewed 237

I'm looking to create a forwarder to collect all published messages on several endpoints and then re-publish those messages with a single publisher. I would like to use ZMQ Proxy object but I'm not sure if this is supported by the library. All the examples of this pattern are fairly simple so it hard to determine if it can be scaled this way.

Can the same backend socket be used in multiple ZMQ proxy objects?

2 Answers

Q : "...ZMQ Proxy object ( for many-to-1 topology )... not sure if this is supported by the library."

No,
at least until the late 2020-Q3, there is no such topology supported in the published ZeroMQ API directly, either in ZeroMQ zmq_proxy() or zmq_proxy_steerable(), the library ready-made Proxy-instance factories.

Yet,
given due design efforts get spent, such a many-to-1 forwarder can be implemented, possibly with some additional, smart features added, irrespective of the choice of the actual target language bindings.

Isn't the ZeroMQ architecture & design so cool and smart?

I don't think that reusing the same socket in multiple proxies is advisable (since each proxy runs in its own thread and zmq sockets aren't thread safe) but the end goal is still possible with a little bit of plumbing.

Just bind a socket to an inproc address (e.g. inproc://proxyinput) and proxy from that socket to your publish socket. Then for each source socket, make a new connection to inproc://proxyinput and proxy from the source to the inproc. Yes, every message gets proxied twice, but the overhead is minimal and everything still works out fine (including subscription propagation if you use XPUB/XSUB sockets).

Related