January 2019
Intermediate to advanced
520 pages
14h 32m
English
In our first example, we'll create a microservice that expects a request with an image, loads it completely to the memory, sends it to a thread for resizing, and waits for the result. Let's start by creating a thread that expects image data and responses. To receive the request, we'll use the mpsc::channel module and oneshot::channel for responses, because multiple clients can't send requests and we only expect one response per image. For the requests, we'll use the following struct:
struct WorkerRequest { buffer: Vec<u8>, width: u16, height: u16, tx: oneshot::Sender<WorkerResponse>,}
WorkerRequest contains the buffer field for binary image data, the desired width and height of the resized image, and ...
Read now
Unlock full access