runng 0.2.0

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

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.