nsq_client/
lib.rs

1// MIT License
2// 
3// Copyright (c) 2019-2021 Alessandro Cresto Miseroglio <alex179ohm@gmail.com>
4// Copyright (c) 2019-2021 Tangram Technologies S.R.L. <https://tngrm.io>
5// 
6// Permission is hereby granted, free of charge, to any person obtaining a copy
7// of this software and associated documentation files (the "Software"), to deal
8// in the Software without restriction, including without limitation the rights
9// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10// copies of the Software, and to permit persons to whom the Software is
11// furnished to do so, subject to the following conditions:
12// 
13// The above copyright notice and this permission notice shall be included in all
14// copies or substantial portions of the Software.
15// 
16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22// SOFTWARE.
23
24//! Nsq-client is the [actix](https://actix.rs) based client implementation of the nsq protocol.
25//!
26//! This crate is intended as a swiss-knife base implementation for more
27//! complex nsq client applications, it supports even single or multiple connections, single or
28//! multiple async readers.
29//!
30//! Due the actors model, readers and connections are distinct entities witch communicate
31//! each other throught messages, so one reader could receive messages from multiple connections and multiple
32//! connections could easily send messages to multiple readers.
33//!
34//!
35//! # Examples
36//! ```no-run
37//! use actix::prelude::*;
38//! use nsq_client::{Connection, Msg, Subscribe, Fin};
39//!
40//! struct MyReader{
41//!     conn: Arc<Addr<Connection>>,
42//! };
43//!
44//! impl Actor for MyReader {
45//!     type Context = Context<Self>;
46//!     fn started(&mut self, _: &mut Self::Context) {
47//!         self.subscribe::<Msg>(ctx, self.conn.clone());
48//!     }
49//! }
50//!
51//! impl Handler<Msg> for MyReader {
52//!     type Result = ();
53//!     fn handle(&mut self, msg: Msg, ctx: &mut Self::Context) {
54//!         let conn = msg.conn.clone();
55//!         let msg = msg.msg;
56//!         info!("MyReader received: {:?}", msg);
57//!         conn.do_send(Fin(msg.id));
58//!     }
59//! }
60//! ```
61
62#![feature(try_from, associated_type_defaults)]
63extern crate futures;
64extern crate tokio_io;
65extern crate tokio_codec;
66extern crate tokio_tcp;
67extern crate bytes;
68extern crate hostname;
69extern crate serde;
70extern crate serde_derive;
71extern crate serde_json;
72extern crate actix;
73extern crate backoff;
74extern crate log;
75extern crate byteorder;
76extern crate fnv;
77
78
79mod codec;
80#[allow(dead_code)]
81mod commands;
82#[allow(dead_code)]
83mod error;
84mod config;
85mod msgs;
86mod producer;
87mod conn;
88mod subscribe;
89mod auth;
90
91pub use subscribe::{Subscribe};
92pub use config::Config;
93pub use producer::{Producer};
94pub use conn::{Connection};
95pub use error::Error;
96pub use msgs::{Fin, Msg, Reqeue, Touch, Pub, InFlight, OnAuth, OnIdentify, Ready, OnBackoff, OnResume, OnClose, Backoff};