#nng #nanomsg #zeromq

runng

High-level wrapper around nng (Nanomsg-Next-Generation) aka Nanomsg2

12 releases

✓ Uses Rust 2018 edition

0.1.11 Jan 29, 2019
0.1.10 Jan 19, 2019
0.1.7 Dec 5, 2018
0.1.5 Nov 29, 2018
0.1.1 Oct 12, 2018

#274 in Network programming

Download history 3/week @ 2019-02-11 4/week @ 2019-02-18 19/week @ 2019-02-25 15/week @ 2019-03-04 5/week @ 2019-03-11 6/week @ 2019-03-18 53/week @ 2019-03-25 12/week @ 2019-04-01 5/week @ 2019-04-08 4/week @ 2019-04-15 13/week @ 2019-04-22 2/week @ 2019-04-29 12/week @ 2019-05-06 25/week @ 2019-05-13 54/week @ 2019-05-20

77 downloads per month
Used in 1 crate

MIT license

1.5MB
55K SLoC

C 52K SLoC // 0.1% comments Rust 2.5K SLoC // 0.1% comments Shell 647 SLoC // 0.2% comments C++ 61 SLoC // 0.1% comments

Rust high-level wrapper around NNG (Nanomsg-Next-Gen):

NNG, like its predecessors nanomsg (and to some extent ZeroMQ), is a lightweight, broker-less library, offering a simple API to solve common recurring messaging problems, such as publish/subscribe, RPC-style request/reply, or service discovery. The API frees the programmer from worrying about details like connection management, retries, and other common considerations, so that they can focus on the application instead of the plumbing.

Features:

Examples

Simple:

use runng::*;
fn test() -> Result<(), NngFail> {
    const url: &str = "inproc://test";
    let factory = Latest::default();
    let rep = factory.replier_open()?.listen(&url)?;
    let req = factory.requester_open()?.dial(&url)?;
    req.send(msg::NngMsg::new()?)?;
    rep.recv()?;
    Ok(())
}

Asynchronous I/O:

use futures::{
    future::Future,
    stream::Stream,
};
use runng::{
    *,
    protocol::{
        AsyncReply,
        AsyncRequest,
        AsyncSocket,
    },
};

fn aio() -> NngReturn {
    const url: &str = "inproc://test";

    let factory = Latest::default();
    let mut rep_ctx = factory
        .replier_open()?
        .listen(&url)?
        .create_async_context()?;

    let requester = factory.requester_open()?.dial(&url)?;
    let mut req_ctx = requester.create_async_context()?;
    let req_future = req_ctx.send(msg::NngMsg::new()?);
    rep_ctx.receive()
        .take(1).for_each(|_request|{
            let msg = msg::NngMsg::new().unwrap();
            rep_ctx.reply(msg).wait().unwrap();
            Ok(())
        }).wait();
    req_future.wait().unwrap()?;

    Ok(())
}

Additional examples in examples/ folder.

Dependencies

~3MB
~64K SLoC