Handlers

Now we can implement gRPC methods of the Ring service we declared in the ring.proto file before. We have the Ring trait with the same names of the methods. Every method expects the Empty value and has to return this type, because we defined this in the declaration. Also, every method has to return the SingleResponse type as a result. We already defined the send_action method that sends the Action value to a worker and returns the SingleResponse response with the Empty value. Let's use the send_action method for both methods we have to implement:

impl Ring for RingImpl {
fn start_roll_call(&self, _: RequestOptions, _: Empty) -> SingleResponse<Empty> {
trace!("START_ROLL_CALL");
self.send_action(Action::StartRollCall)
}

fn mark_itself(&self, _: RequestOptions, _: Empty) -> SingleResponse<Empty> {
trace!("MARK_ITSELF");
self.send_action(Action::MarkItself)
}
}

We have a pretty simple implementation of gRPC methods handlers, but you can also add more sensible implementations and produce SingleResponse from a Future asynchronously.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.133.233