January 2019
Intermediate to advanced
520 pages
14h 32m
English
Add a new struct called QueueActor and add a type parameter that implements the QueueHandler trait:
pub struct QueueActor<T: QueueHandler> { channel: Channel<TcpStream>, handler: T, }
The struct has a reference to a connection Channel to RabbitMQ. We build it over TcpStream. The struct also has a handler field that contains an instance of a handler that implements QueueHandler.
This struct also has to implement the Actor trait to become an actor. We also added a started method. It remains empty, but it's a good place to create all the queues. For example, you can create a message type that will attach a Stream of messages to this actor. With this approach, you can start consuming any queue at any time:
impl<T: QueueHandler> Actor for ...
Read now
Unlock full access