[][src]Struct nsq_client::Backoff

pub struct 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]

type Result = ()

The type of value that this handle will return

Auto Trait Implementations

impl Send for Backoff

impl Sync for Backoff

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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.

impl<T> Erased for T