Library for communicating between services

Hello! I'm looking for a way to communicate between different Rust services that are running on different machines. Basically, I'm going to have one "client" program that fetches data from various "server" programs that the user can choose between. I've looked at various options like ZeroMQ, NATS, or even just writing my own protocol, but I'm asking here to see if there's anything that I haven't considered yet. Here are my requirements, roughly in order of priority:

  • Doesn't require an external broker/server
  • Supports both request-reply and bidirectional-style communication
  • Is hopefully able to multiplex both of those on one connection
  • Can communicate over both network (TCP) and locally (Unix sockets or something similar)
  • Is relatively lightweight and adds little overhead to the code
  • Can automatically reconnect broken connections

I understand that this is a pretty specific list, and I might just end up writing my own protocol that operates over a byte stream, but I just wanted to hear if there were any good options that I was missing. Thanks!

We use NATS for all that kind of thing. NATS meets your requirements:
Request/Response and bidirectional.
Multiplex onto a single connection.
Relatively light weight.
Automatically reconnects.

NATS does not meet your requirements in that:
It does require an external broker. Is that really a problem? When one has a number of services running what's the problem with one more for a broker? Especially since NATS is very simple to install, configure and run.

It does not use Unix sockets locally. I would imagine that unless one wants maximum performance then this is not a concern. I also imagine that the kernel does an efficient job of short circuiting local TCP connections.

NATS also offers a lot of other advantages. Like clustering for fault tolerance, security with TLS, isolation of channels using users/groups etc.

A NATS written in Rust would be great of course but I see no pressing need to write such a thing.

To put it simply, I'm writing a self-hosted application that people will be installing on their own devices. I want to minimize the amount of additional things they need to install and have running to get my app set up.

I can appreciate that. We do pretty much the same. Getting NATS installed and running is so simple though that we tolerate the "additional thing".

2 Likes

Possibly remoc - Rust

I have been recommended this (my use case is Unix sockets for privilege separation). I have yet to get to implementing privsep in my project though, so I don't know how good it is.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.