Crate apalis_amqp

source ·
Expand description

§apalis-amqp

Message queuing utilities for Rust using apalis and AMQP.

§Overview

apalis-amqp is a Rust crate that provides utilities for integrating apalis with AMQP message queuing systems. It includes an AmqpBackend implementation for use with the pushing and popping jobs, as well as a MessageQueue<J> implementation for consuming messages from an AMQP queue and passing them to Worker for processing.

§Features

  • Integration between apalis and AMQP message queuing systems.
  • Easy creation of AMQP-backed job queues.
  • Simple consumption of AMQP messages as apalis jobs.
  • Supports message acknowledgement and rejection via tower layers.
  • Supports all apalis middleware such as rate-limiting, timeouts, filtering, sentry, prometheus etc.

§Getting started

Add apalis-amqp to your Cargo.toml file:

[dependencies]
apalis = { version = "0.5", features = ["tokio-comp"] }
apalis-amqp = "0.3"
serde = "1"

Then add to your main.rs

use apalis::prelude::*;
use apalis_amqp::AmqpBackend;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
struct TestJob(usize);
impl Message for TestJob {
    const NAME: &'static str = "TestJob";
}
async fn test_job(job: TestJob) {
    dbg!(job);
}

#[derive(Clone, Debug, Default)]
pub struct TokioExecutor;

impl apalis_core::executor::Executor for TokioExecutor {
  fn spawn(&self, future: impl std::future::Future<Output = ()> + Send + 'static) {
       tokio::spawn(future);
   }
}
#[tokio::main]
async fn main() {
    let env = std::env::var("AMQP_ADDR").unwrap();
    let mq = AmqpBackend::<TestJob>::new_from_addr(&env).await.unwrap();
    mq.enqueue(TestJob(42)).await.unwrap();
    Monitor::<TokioExecutor>::new()
        .register(
            WorkerBuilder::new("rango-amigo")
                .with_mq(mq)
                .build_fn(test_job),
        )
        .run()
        .await
        .unwrap();
}

Structs§

  • A wrapper around a lapin AMQP channel that implements message queuing functionality.
  • A wrapper for the the job to be acknowledged.