[][src]Crate runng

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::create()?)?;
    rep.recv()?;
    Ok(())
}

Asynchronous I/O:

use futures::{
    future::Future,
    stream::Stream,
};
use runng::{
    *,
    asyncio::*,
    protocol::*,
};

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

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

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

    Ok(())
}

Additional examples in examples/ folder.

Re-exports

pub use self::aio::*;
pub use self::ctx::*;
pub use self::factory::*;
pub use self::options::*;
pub use self::result::*;
pub use self::socket::*;

Modules

aio

Asynchronous I/O

asyncio

NNG protocols. See Section 7.

ctx

Protocol contexts

dialer

Dialer

factory
listener

Listener

msg
options

NNG options. See nng_options.

pipe

Pipe

protocol

NNG protocols. See Section 7.

result

Return values and error handling

socket

Socket basics

stats

Runtime statistics

transport

NNG transports. See Section 7.