A Actix based client implementation for the NSQ realtime message processing system.
To use nsq-client, add this to your Cargo.toml:
toml
[dependencies]
actix = "0.7"
nsq-client = "0.1.2"
In order to use nsq-client you first need to create a Reader actor which implement Handler for the type of messages you want to receive from the connections and then subscribe it to the connections to be able to receive the type of messages you've selected.
Available messages are: - Msg nsqd messages sent to the Connection (routed to your Reader) - InFlight Connection message sent to the reader every time inflight is increased or decreased
```rust extern crate nsqueue; extern crate actix;
use std::sync::Arc;
use actix::prelude::*;
use nsqueue::{Connection, Msg, Fin, Subscribe, Config};
struct MyReader {
pub conn: Arc
impl Actor for MyReader {
type Context = Context
impl Handler
fn main() { let sys = System::new("consumer"); let config = Config::default().clientid("consumer"); let c = Supervisor::start(|| Connection::new( "test", // <- topic "test", // <- channel "0.0.0.0:4150", // <- nsqd tcp address Some(config), // <- config (Optional) None, // secret for Auth (Optional) Some(2) // <- RDY (Optional default: 1) )); let conn = Arc::new(c); let _ = MyReader{ conn: conn.clone() }.start(); // <- Same thread reader let _ = Arbiter::start(|_| MyReader{ conn: conn }); // <- start another reader in different thread sys.run(); } ```
bash
$ nsqd -verbose
bash
$ RUST_LOG=nsq_client=debug cargo run
bash
$ cargo run
Licensed under * MIT license (see LICENSE or http://opensource.org/licenses/MIT)