Message broker for rust recomendation


#1

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?


#2

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


#3

ok @robsmith11 I will check them thank you!


#4

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)?;
    sock.connect(addr)?;

    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);

    Ok(())
}

fn run_server(ctx: &mut Context, addr: &str) -> Result<(), Error> {
    let sock = ctx.socket(zmq::REP)?;
    sock.connect(addr)?;
    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://127.0.0.1:5559";
    let addr_backend = "tcp://127.0.0.1:5559";

    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.


#5

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.


#6

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.


#7

The entire ZeroMQ book is on-line:
http://zguide.zeromq.org/page:all

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.