Crates.io | apalis-amqp |
lib.rs | apalis-amqp |
version | 0.4.0-rc.1 |
source | src |
created_at | 2023-04-09 17:47:25.184329 |
updated_at | 2024-07-25 20:42:03.543477 |
description | Message queuing utilities for Rust using apalis and Amqp |
homepage | |
repository | https://github.com/geofmureithi/apalis-amqp |
max_upload_size | |
id | 834455 |
size | 30,821 |
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 messages, as well as a MessageQueue<M>
implementation for consuming messages from an AMQP queue.
tower
layers.Before attempting to connect, you need a working amqp backend. We can easily setup using Docker:
docker run -p 15672:15672 -p 5672:5672 -e RABBITMQ_DEFAULT_USER=apalis -e RABBITMQ_DEFAULT_PASS=apalis rabbitmq:3.8.4-management
Add apalis-amqp to your Cargo.toml
[dependencies]
apalis = "0.6"
apalis-amqp = "0.4"
serde = "1"
Then add to your main.rs
use apalis::prelude::*;
use apalis_amqp::AmqpBackend;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
struct TestMessage(usize);
async fn test_message(message: TestMessage) {
dbg!(message);
}
#[tokio::main]
async fn main() {
let env = std::env::var("AMQP_ADDR").unwrap();
let mq = AmqpBackend::<TestMessage>::new_from_addr(&env).await.unwrap();
// This can be in another place in the program
mq.enqueue(TestMessage(42)).await.unwrap();
Monitor::<TokioExecutor>::new()
.register(
WorkerBuilder::new("rango-amigo")
.backend(mq)
.build_fn(test_message),
)
.run()
.await
.unwrap();
}
Run your code and profit!
apalis-amqp is licensed under the Apache license. See the LICENSE file for details.