Quantcast
Channel: Active questions tagged zeromq - Stack Overflow
Viewing all articles
Browse latest Browse all 193

How could I accomplish the equivalent of a ROS service in ZeroMQ?

$
0
0

In short: How could I realize something like a "Service" from ROS in ZMQ?


ROS2 is typically based on subscribers and publishers to topics, in the same way that ZeroMQ uses them: messages are published under a path and only clients that are subscribed to (a base of) that path receive it.
But ROS2 also has a concept called services (docs), where a request is pushed to an address and a server-like thing listening to that address will send a reply. A nice GIF:

What is great about this concept, is the service client doesn't need to know who hosts the service. They are matched only by a name.

In ZMQ I am hoping to achieve something similar: I have a bunch of functions (services?) that I want to distribute over a set of sockets (servers). I want those services to connect to a single client and have this client make calls without the client having to know is going to be connected beforehand (e.g. by calling a service by name only).

So the client might make calls to:

/machine/valve/machine/leds/global/state

And will receive replies from them. But maybe from a single or 2 or 3 different nodes, depending on what's running.


One option would be to use PUB-SUB and SUB-PUB in ZMQ for these kind of commands. The client would also bind a subscriber to listen to confirmations published for the commands. But some limitations are: i) the publisher won't know if there are no subscribers, ii) there is no way to tell if the published message got dropped, iii) there is no way to prevent multiple nodes listening to the same topic, resulting in double execution of functions.

The other option is REQ-REP, where the client binds a REQ for each feature and nodes connect with REQ. The main downside here is the client already has to split up the functionality beforehand.


Viewing all articles
Browse latest Browse all 193

Trending Articles