[][src]Struct riker::actor::Channel

pub struct Channel<Msg: Message> { /* fields omitted */ }

A specialized actor for providing Publish/Subscribe capabilities to users.

It is a common actor pattern to provide pub/sub features to other actors especially in cases where choreography (instead of orchestration) is used. See: Service Choreography

A channel can be started as you would any other actor. A channel expects ChannelMsg messages.

To publish a message to a channel you send the channel a ChannelMsg::Publish message containing the topic and the message to publish.

A published message is cloned and sent to each subscriber to the channel where the topic matches.

To subscribe to a channel you send the channel a ChannelMsg::Subscribe message containing the topic to subscribe to and an ActorRef of the subscriber (e.g. .myself()).

Since channels are actors themselves they provide excellent lightweight facilitators of distributing data among actors that are working together to complete a single goal or interaction (even short lived interactions).


use riker::actors::ChannelMsg::*;
struct MyActor;
impl Actor for MyActor {
    type Msg = String;

    fn receive(&mut self,
                ctx: &Context<Self::Msg>,
                msg: Self::Msg,
                sender: Option<ActorRef<Self::Msg>>) {
        println!("Received msg {:?}", msg);
impl MyActor {
    fn actor() -> BoxActor<String> {
// main
let model: DefaultModel<String> = DefaultModel::new();
let sys = ActorSystem::new(&model).unwrap();

// start two instances of MyActor
let props = Props::new(Box::new(MyActor::actor));
let sub1 = sys.actor_of(props.clone(), "sub1").unwrap();
let sub2 = sys.actor_of(props, "sub2").unwrap();
// start a channel
let chan = sys.actor_of(Channel::props(), "my-channel").unwrap();
// subscribe actors to channel
chan.tell(Subscribe("my-topic".into(), sub1), None);
chan.tell(Subscribe("my-topic".into(), sub2), None);
// publish a message
let msg = Publish("my-topic".into(), "Remember the cant!".into());
chan.tell(msg, None);


impl<Msg: Message> Channel<Msg>[src]

pub fn new(event_stream: Option<ActorRef<Msg>>) -> BoxActor<Msg>[src]

pub fn props() -> BoxActorProd<Msg>[src]

Trait Implementations

impl<Msg: Message> Actor for Channel<Msg>[src]

type Msg = Msg

fn post_start(&mut self, ctx: &Context<Self::Msg>)[src]

Invoked after an actor has started. Read more

fn post_stop(&mut self)[src]

Invoked after an actor has been stopped.

fn persistence_conf(&self) -> Option<PersistenceConf>[src]

Return a Some(PersistenceConf) to enable actor persistence. Read more

fn apply_event(
    &mut self,
    ctx: &Context<Self::Msg>,
    evt: Self::Msg,
    sender: Option<ActorRef<Self::Msg>>

Invoked after an event is successfully inserted into the event store. Read more

fn replay_event(&mut self, ctx: &Context<Self::Msg>, evt: Self::Msg)[src]

Invoked for each event when the actor is recovering. Read more

fn supervisor_strategy(&self) -> Strategy[src]

Return a supervisor strategy that will be used when handling failed child actors.

Auto Trait Implementations

impl<Msg> Send for Channel<Msg>

impl<Msg> Sync for Channel<Msg>

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized

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

impl<T> BorrowMut for T where
    T: ?Sized

impl<T, U> TryInto for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.