Message broker for rust recomendation

I want to start a project and I want to use message broker like rabbitmq. which do you recommend for rust?
which is easier to use and has good documentation?

1 Like

I usually use zeromq or nanomsg when I want easy cross-platform messaging. They’re simple, performant, and have good rust support.

1 Like

ok @robsmith11 I will check them thank you!

I was checking zeromq and my questions how can I archive to have multiple queue server like Rabbitmq?

extern crate zmq;

use zmq::{Context, Message, Error};
use std::env;

fn run_client(ctx: &mut Context, addr: &str) -> Result<(), Error> {
    let sock = ctx.socket(zmq::REQ)?;

    let payload = "Hello world!";
    println!("-> {:?}", payload);

    let mut msg = Message::new();
    sock.send(payload.as_bytes(), 0)?;
    sock.recv(&mut msg, 0)?;
    let contents = msg.as_str().unwrap();
    println!("<- {:?}", contents);


fn run_server(ctx: &mut Context, addr: &str) -> Result<(), Error> {
    let sock = ctx.socket(zmq::REP)?;
    let mut msg = Message::new();

    loop {
        if sock.recv(&mut msg, 0).is_ok() {
            let contents = msg.as_str().unwrap();
            println!("{:?}", contents);
            sock.send(contents.as_bytes(), 0)?;

fn main() {
    let args: Vec<String> = env::args().collect();

    if args.len() < 2 {
        eprintln!("Usage: {} (client|server)", args[0]);

    let mut ctx = Context::new();
    let addr_frontend = "tcp://";
    let addr_backend = "tcp://";

    if args[1] == "client" {
        println!("ZeroMq client connecting to {}", addr_frontend);
        run_client(&mut ctx, addr_frontend).unwrap_or_else(|err| eprintln!("{:?}", err));
    } else {
        println!("ZeroMq server listening on {}", addr_backend);
        run_server(&mut ctx, addr_backend).unwrap_or_else(|err| eprintln!("{:?}", err));

In this example I cannot run more than one server because it throws the address is already used but I cannot archive to have multiple server which recieve the message in queue way.

ZeroMQ is really performant, and the Rust support for it is awesome. But I’ve always viewed ZMQ as a lower-level toolkit with a lot of gotcha’s. The broker systems have a more out-of-the-box feel to them, and can usually get a fairly reliable system up and running with less development time.

AMQP with RabbitMQ is one of my favorites for big systems, but MQTT is also very popular, especially with the cloud IoT services (AWS, Azure, etc), if you are working with little devices especially that might be using unreliable connections (WiFi, Cell modems, etc). You can use RabbitMQ for that as well, but Mosquitto is very popular.

That said, I’m a little biased since I work on some MQTT libraries, but I use ZeroMQ a lot. There are overlapping use cases, but sometimes one seems a better fit for a particular application.

1 Like

Ok I get it, I spend a lot time to understand that. Suposelly the server is which bind and the clients is which connect and you can have several connections in one server. What I don’t know is how I can connect between diferents port.

The entire ZeroMQ book is on-line:

Most of the examples in the book are rewritten for Rust as examples in the crate, You can clone them or check them out on GitHub:

So it’s easy to reads through the book and then see how to use the examples in Rust.

1 Like