Dependencies

Create a new library crate (in which we will add two binaries later) called rabbit-actix:

[package]
name = "rabbit-actix"
version = "0.1.0"
edition = "2018"

As you can see, we are using the 2018 edition of Rust. We need a pretty big pile of crates:

[dependencies]
actix = "0.7"
actix-web = "0.7"
askama = "0.7"
chrono = "0.4"
env_logger = "0.6"
image = "0.21"
indexmap = "1.0"
failure = "0.1"
futures = "0.1"
log = "0.4"
queens-rock = "0.1"
rmp-serde = "0.13"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
tokio = "0.1"
uuid = "0.7"

It's important to note that we use the actix framework with the actix-web crate. If you are not familiar with this crate, you can read more about it in Chapter 11, Involving Concurrency with Actors and Actix Crate. We also use the image crate to work with image formats, because this crate is used by queens-rock and implements a decoder for QR codes. We also use the askama crate to render HTML pages with posted tasks, and we use the indexmap crate to get an ordered hash map that keeps elements insertion order. To create unique names for the tasks, we will use the UUID4 format, which is implemented in the uuid crate.

To interact with RabbitMQ, we will use the lapin-futures crate, but we renamed it lapin because there are two implementations of this crate. The one that we use is based on the futures crate, and there is also the lapin-async crate version based on the mio crate. We will use the lapin-futures crate first, and name it lapin:

[dependencies.lapin]
version = "0.15"
package = "lapin-futures"

Add the first binary with a server implementation pointing to the src/server.rs file:

[[bin]]
name = "rabbit-actix-server"
path = "src/server.rs"
test = false

Add the second binary for a worker that will be implemented in the src/worker.rs file:

[[bin]]
name = "rabbit-actix-worker"
path = "src/worker.rs"
test = false

We already use the askama crate as a dependency for the main code, but we also need it as a dependency for the build.rs script. Add this:

[build-dependencies]
askama = "0.7"

The preceding dependency needs to rebuild templates to embed them into code. Add the following code to a new build.rs script:

fn main() {
askama::rerun_if_templates_changed();
}

All the dependencies are prepared, and we can create an abstract type to interact with queues in a message broker.

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

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