Crates.io | nng_async |
lib.rs | nng_async |
version | 0.2.0 |
source | src |
created_at | 2019-10-28 09:03:36.288199 |
updated_at | 2019-10-28 09:03:36.288199 |
description | High-level wrapper around nng (Nanomsg-Next-Generation) aka Nanomsg2 |
homepage | |
repository | https://github.com/jeikabu/runng |
max_upload_size | |
id | 176324 |
size | 178,256 |
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:
async
/await
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 examples/
folder and runng_examples.