MCPcopy Index your code
hub / github.com/densumesh/broccoli

github.com/densumesh/broccoli @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
227 symbols 869 edges 28 files 78 documented · 34%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Broccoli

Crates.io Docs.rs License

A robust message queue system for Rust applications, designed as a Rust alternative to Celery. Currently Redis-backed, with planned support for RabbitMQ, Kafka, and other message brokers. This is by no means a finished product, but we're actively working on it and would love your feedback and contributions!

Features

  • Asynchronous message processing
  • Redis-backed persistence (with RabbitMQ and Kafka support planned)
  • Configurable retry strategies
  • Connection pooling
  • Type-safe message handling
  • Error handling with custom handlers
  • Flexible message processing patterns

Installation

Add this to your Cargo.toml:

[dependencies]
broccoli_queue = "0.1.0"

Quick Start

Producer

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
    let queue = BroccoliQueue::builder("redis://localhost:6379")
        .pool_connections(5) // Optional: Number of connections to pool
        .failed_message_retry_strategy(Default::default()) // Optional: Retry strategy (max retries, etc)
        .build()
        .await?;

    // Create some example jobs
    let jobs = vec![
        JobPayload {
            id: "job-1".to_string(),
            task_name: "process_data".to_string(),
        },
        JobPayload {
            id: "job-2".to_string(),
            task_name: "generate_report".to_string(),
        },
    ];

    // Publish jobs in batch
    queue.publish_batch(
        "jobs", // Queue name
         jobs // Jobs to publish
    ).await?;

    Ok(())
}

Consumer

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
    let queue = BroccoliQueue::builder("redis://localhost:6379")
        .pool_connections(5)
        .failed_message_retry_strategy(Default::default()) // Optional: Retry strategy (max retries, etc)
        .build()
        .await?;

    // Process messages
    queue.process_messages(
        "jobs", // Queue name
        Some(2), // Optional: Number of worker threads to spin up
        |message: BrokerMessage<JobPayload>| async move { // Message handler
            println!("Processing job: {:?}", message);
            Ok(())
        },
    ).await?;

    Ok(())
}

Why Broccoli?

If you're familiar with Celery but want to leverage Rust's performance and type safety, Broccoli is your answer. While currently focused on Redis as the message broker, we're actively working on supporting multiple brokers to provide the same flexibility as Celery:

  • Redis (Current)
  • RabbitMQ (Planned)
  • Kafka (Planned)
  • And more to come!

This multi-broker approach will allow you to choose the message broker that best fits your needs while maintaining a consistent API.

Documentation

Roadmap

  • [x] Redis broker implementation
  • [x] RabbitMQ broker support
  • [ ] Kafka broker support
  • [ ] Proc macros for building workers
  • [ ] Additional message patterns
  • [ ] Enhanced monitoring and metrics
  • [ ] Web interface for job monitoring

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. We're particularly interested in contributions for:

  • New broker implementations
  • Additional message patterns
  • Performance improvements
  • Documentation enhancements
  • Bug fixes

Extension points exported contracts — how you extend this code

QueueManagement (Interface)
Trait for managing the state of broccoli queues. [2 implementers]
src/brokers/management.rs
Broker (Interface)
(no doc) [3 implementers]
src/brokers/broker.rs
BrokerWithManagement (Interface)
(no doc) [2 implementers]
src/brokers/management.rs

Core symbols most depended-on inside this repo

clone
called by 116
src/queue.rs
publish
called by 48
src/queue.rs
build
called by 44
src/queue.rs
setup_queue
called by 33
tests/common/mod.rs
acknowledge
called by 27
src/queue.rs
fairness
called by 23
src/queue.rs
get_redis_client
called by 21
tests/common/mod.rs
publish_batch
called by 18
src/queue.rs

Shape

Function 101
Method 85
Class 34
Enum 4
Interface 3

Languages

Rust100%

Modules by API surface

src/brokers/surrealdb/utils.rs43 symbols
src/queue.rs40 symbols
tests/happy_path.rs18 symbols
benches/surrealdb_benchmark.rs16 symbols
src/brokers/surrealdb/broker.rs13 symbols
tests/edge_cases.rs12 symbols
src/brokers/broker.rs11 symbols
src/brokers/redis/broker.rs9 symbols
src/brokers/rabbitmq/broker.rs9 symbols
src/brokers/redis/utils.rs7 symbols
tests/management.rs6 symbols
examples/consumer.rs6 symbols

For agents

$ claude mcp add broccoli \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact