Crate requeuest

Source
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::Request;

let request = Request::get("https://foo.bar/_api/baz")?.build();
client.spawn("my_service", &request).await?;

You can also also get the response back from a successfully delivered request.


let request = Request::post("https://example.com/_api/bar/foo", Vec::from("some data"))?.build();
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}

Re-exports§

pub use client::Client;
pub use request::Request;
pub use reqwest;

Modules§

client
The Client holds the job listener and database connection, which is used to spawn jobs.
error
Errors specific to this crate.
request
Contains the definition of the request which gets (de)serialized and sent to the database

Structs§

HeaderMap
A set of HTTP headers
Method
The Request Method (VERB)
Pool
An asynchronous pool of SQLx database connections.
Postgres
PostgreSQL database driver.
Url
A parsed URL record.
Uuid
A Universally Unique Identifier (UUID).

Enums§

ParseError
Errors that can occur during parsing.

Functions§

migrate
Runs the SQL migrations this library needs.