Skip to main content

Broccoli

A robust message queue system for Rust applications, designed as a Rust alternative to Celery. Broccoli provides asynchronous message processing with type safety, configurable retry strategies, and support for multiple message brokers.

Features

Type-safe messaging

Leverage Rust’s type system for compile-time message validation

Multiple brokers

Support for Redis, RabbitMQ, and SurrealDB backends

Configurable retries

Built-in retry strategies for failed message handling

Connection pooling

Efficient resource management with connection pools

Message scheduling

Schedule messages for delayed or future delivery

Concurrent processing

Process messages with configurable worker concurrency

Quick example

use broccoli_queue::{queue::BroccoliQueue, brokers::broker::BrokerMessage};
use serde::{Serialize, Deserialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
struct JobPayload {
    id: String,
    task_name: String,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize the queue with Redis
    let queue = BroccoliQueue::builder("redis://localhost:6379")
        .pool_connections(5)
        .failed_message_retry_strategy(Default::default())
        .build()
        .await?;

    // Publish a message
    let job = JobPayload {
        id: "job-1".to_string(),
        task_name: "process_data".to_string(),
    };
    
    queue.publish("jobs", None, &job, None).await?;

    // Process messages
    queue.process_messages("jobs", Some(2), None, |message: BrokerMessage<JobPayload>| async move {
        println!("Processing: {:?}", message.payload);
        Ok(())
    }).await?;

    Ok(())
}

Why Broccoli?

If you’re familiar with Celery but want to leverage Rust’s performance and type safety, Broccoli provides:
  • Rust performance - Native async/await with Tokio runtime
  • Type safety - Compile-time message validation with serde
  • Multiple brokers - Choose Redis, RabbitMQ, or SurrealDB based on your needs
  • Simple API - Builder pattern for easy configuration

Current status

Broccoli is under active development. Current broker support:
BrokerStatus
Redis✅ Available
RabbitMQ✅ Available
SurrealDB✅ Available
Kafka🚧 Planned