Bonsaimq
Simple database message queue based on bonsaidb.
The project is highly influenced by sqlxmq.
Warning: This project is in early alpha and should not be used in production!
Usage
Import the project using:
or
# adjust the version to the latest version:
= "0.3.0"
# or
= { = "https://github.com/FlixCoder/bonsaimq" }
Then you can use the message/job queue as follows:
- You need job handlers, which are async functions that receive one argument of type
CurrentJob
and return nothing.CurrentJob
allows interfacing the job to retrieve job input or complete the job etc. - The macro
job_regristy!
needs to be use to create a job registry, which maps message names/types to the job handlers and allows spawning new jobs. - A job runner needs to be created and run on a bonsai database. It runs in the background as long as the handle is in scope and executes the jobs according to the incoming messages. It acts on the job registry.
Example
Besides the following simple example, see the examples in the examples folder and take a look at the tests.
use ;
use ;
use Result;
/// Example job function. It receives a handle to the current job, which gives
/// the ability to get the input payload, complete the job and more.
async
// The JobRegistry provides a way to spawn new jobs and provides the interface
// for the JobRunner to find the functions to execute for the jobs.
job_registry!;
async
Lints
This projects uses a bunch of clippy lints for higher code quality and style.
Install cargo-lints
using cargo install --git https://github.com/FlixCoder/cargo-lints
. The lints are defined in lints.toml
and can be checked by running cargo lints clippy --all-targets --workspace
.