Crates.io | nsqueue |
lib.rs | nsqueue |
version | 0.1.5 |
source | src |
created_at | 2017-05-29 21:50:25.885476 |
updated_at | 2017-07-08 10:09:53.505782 |
description | Rust client for the NSQ realtime message processing system |
homepage | |
repository | https://github.com/wisespace-io/nsqueue |
max_upload_size | |
id | 16828 |
size | 27,527 |
A Tokio based client implementation for the NSQ realtime message processing system
$ ./nsqlookupd &
$ ./nsqd --lookupd-tcp-address=127.0.0.1:4160 &
$ ./nsqadmin --lookupd-http-address=127.0.0.1:4161 &
extern crate futures;
extern crate tokio_core;
extern crate nsqueue;
use futures::Future;
use tokio_core::reactor::Core;
use nsqueue::config::*;
use nsqueue::producer::*;
fn main() {
let mut core = Core::new().unwrap();
let handle = core.handle();
let addr = "127.0.0.1:4150".parse().unwrap();
let mut messages: Vec<String> = Vec::new();
messages.push("First message".into());
messages.push("Second message".into());
let res = Producer::connect(&addr, &handle, Config::default())
.and_then(|conn| {
conn.mpublish("some_topic".into(), messages)
.and_then(move |response| {
println!("Response: {:?}", response);
Ok(())
})
});
core.run(res).unwrap();
}
extern crate futures;
extern crate tokio_core;
extern crate nsqueue;
use futures::{Stream, Future};
use tokio_core::reactor::Core;
use nsqueue::config::*;
use nsqueue::consumer::*;
fn main() {
let mut core = Core::new().unwrap();
let handle = core.handle();
let addr = "127.0.0.1:4150".parse().unwrap();
core.run(
Consumer::connect(&addr, &handle, Config::default())
.and_then(|conn| {
conn.subscribe("some_topic".into(), "some_channel".into())
.and_then(move |response| {
let ret = response.for_each(move |message| {
if message.message_id == "_heartbeat_" {
conn.nop();
} else {
println!("Response {:?} {:?}", message.message_id, message.message_body);
conn.fin(message.message_id); // Inform NSQ (Message consumed)
}
Ok(())
});
ret
})
})
).unwrap();
}
Licensed under either of