Crate requeuest[−][src]
Expand description
Requeuest is a library for queueing the sending of HTTP requests. It’s built with the sqlxmq crate, which is a message queue that uses a postgres database for storing messages.
Getting started
Assuming you already have an sqlx connection to a postgres database, you
will first need to run migrations so the needed tables and SQL functions can
get set up on your postgres database.
requeuest::migrate(&pool).await?;Once that’s taken care of, start by constructing a client. This is what you
will use to spawn requests, an what will execute jobs in the background. It
will keep doing so until it is dropped. The client contains a tokio
JoinHandle which you can remove from the client with
Client::take_listener if you want the
listener to keep running after the client has dropped, or otherwise
interface with the background task directly.
use requeuest::{Client, client::Channels};
let client = Client::new(pool, Channels::List(&["my_service"])).await?;After the client has been constructed, you can begin spawning jobs. Here we send a get request to an example address:
use requeuest::{HeaderMap, Request};
let request = Request::get("https://foo.bar/_api/baz".parse()?, HeaderMap::new());
client.spawn("my_service", &request).await?;You can also also get the response back from a successfully delivered request.
// You can skip the HeaderMap import by invoking the constructor via the Default trait
let request = Request::post("https://example.com/_api/bar/foo".parse()?, Vec::from("some data"), Default::default());
let response = client.spawn_returning("my_service", &request).await?;Note that the spawn_returning method will wait indefinitely (or to be
precise, roughly 10^293 years) until a successful response is received, so
this will wait forever if a request is sent to e.g. an unregistered domain,
or sends data to an API which will always result in a non-200 response code.
Features
This crate has the following features:
http: Enable conversion of requests from the [http] crate- Async runtime and TLS implementation for
sqlx:- Any of
runtime-{tokio,actix,async-std}-{rustls,native-tls}
- Any of
Re-exports
Modules
The Client holds the job listener and database connection, which is used
to spawn jobs.
Errors specific to this crate.
Contains the definition of the request which gets (de)serialized and sent to the database
Structs
A set of HTTP headers
The Request Method (VERB)
A parsed URL record.
A Universally Unique Identifier (UUID).
Functions
Runs the SQL migrations this library needs.