#nng #nanomsg #zeromq #runng

runng

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

13 releases

✓ Uses Rust 2018 edition

0.3.2 Jan 14, 2020
0.3.1 Jan 11, 2020
0.2.0 Oct 19, 2019
0.1.11 Jan 29, 2019
0.1.1 Oct 12, 2018

#514 in Network programming

Download history 20/week @ 2019-10-14 51/week @ 2019-10-21 110/week @ 2019-10-28 29/week @ 2019-11-04 2/week @ 2019-11-11 41/week @ 2019-11-18 16/week @ 2019-11-25 39/week @ 2019-12-02 166/week @ 2019-12-09 2/week @ 2019-12-16 15/week @ 2019-12-23 1/week @ 2019-12-30 29/week @ 2020-01-06 48/week @ 2020-01-13 52/week @ 2020-01-20

179 downloads per month
Used in runng_thrift

MIT license

130KB
3K SLoC

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::{
    Dial, Listen, RecvMsg, SendMsg,
    factory::latest::ProtocolFactory, 
    msg::NngMsg,
    protocol::*,
};
fn simple_reqrep() -> Result<(), runng::Error> {
    const url: &str = "inproc://test";

    let factory = ProtocolFactory::default();
    let rep = factory.replier_open()?.listen(&url)?;
    let req = factory.requester_open()?.dial(&url)?;
    req.sendmsg(NngMsg::create()?)?;
    rep.recv()?;

    Ok(())
}

Asynchronous I/O:

use futures::{
    future::Future,
    stream::Stream,
};
use runng::{
    Dial, Listen,
    asyncio::*,
    factory::latest::ProtocolFactory,
    msg::NngMsg,
    protocol::*,
};

fn async_reqrep() -> Result<(), runng::Error> {
    const url: &str = "inproc://test";

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

    let mut req_ctx = factory.requester_open()?.dial(&url)?.create_async()?;
    let req_future = req_ctx.send(NngMsg::create()?);
    let _request = rep_ctx.receive().wait()?;
    rep_ctx.reply(NngMsg::create()?).wait()??;
    req_future.wait().unwrap()?;

    Ok(())
}

Additional examples in tests/ folder and runng_examples.

Dependencies

~4.5MB
~114K SLoC