[−][src]Struct nsq_client::Backoff
Allows Consumer to set Connection on backoff state
Examples
use actix::prelude::*;
use nsq_client::{Subscribe, Connection, Backoff, OnBackoff, OnResume, InFlight, Ready};
struct Consumer{
conn: Addr<Connection>,
backoff: bool,
};
impl Actor for Consumer {
type Context = Context<Self>;
fn started(&mut self, _: &mut Self::Context) {
self.subscribe::<OnBackoff>(ctx, self.0.clone());
self.subscribe::<OnResume>(ctx, self.0.clone());
self.subscribe::<InFlight>(ctx, self.0.clone());
self.conn.do_send(Ready(10));
self.conn.do_send(Backoff);
}
}
impl Handler<OnBackoff> for Consumer {
type Result = ();
fn handle(&mut self, msg: OnBackoff, _: &mut Self::Context) {
println!("Connection in Backoff");
self.backoff = true;
}
}
impl Handler<OnResume> for Consumer {
type Result = ();
fn handle(&mut self, msg: OnResume, _: &mut Self::Context) {
println!("Connection resuming from backoff");
self.backoff = false;
}
}
impl Handler<OnInflight> for Consumer {
type Result = ();
fn handle(&mut self, msg: OnInFlight, _: &mut Self::Context) {
match msg.0 {
0 => { println!("backoff state: {}", self.backoff) },
1 => { println!("resuming from backoff") },
_ => { println!("throttle") },
}
}
}
Trait Implementations
impl Message for Backoff
[src]
type Result = ()
The type of value that this message will resolved with if it is successful. Read more
impl Handler<Backoff> for Connection
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
🔬 This is a nightly-only experimental API. (
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
🔬 This is a nightly-only experimental API. (
try_from
)The type returned in the event of a conversion error.