> ## Documentation Index
> Fetch the complete documentation index at: https://densumesh-broccoli-27.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Broker Overview

> Supported message brokers and how to choose

## Supported brokers

Broccoli supports multiple message brokers through feature flags:

| Broker    | Feature     | URL Scheme        | Status     |
| --------- | ----------- | ----------------- | ---------- |
| Redis     | `redis`     | `redis://`        | ✅ Stable   |
| RabbitMQ  | `rabbitmq`  | `amqp://`         | ✅ Stable   |
| SurrealDB | `surrealdb` | `ws://`, `mem://` | ✅ Stable   |
| Kafka     | -           | -                 | 🚧 Planned |

## How broker selection works

Broccoli automatically selects the broker based on your connection URL:

```rust theme={null}
// Redis
let queue = BroccoliQueue::builder("redis://localhost:6379").build().await?;

// RabbitMQ
let queue = BroccoliQueue::builder("amqp://localhost:5672").build().await?;

// SurrealDB
let queue = BroccoliQueue::builder("ws://localhost:8000").build().await?;
```

<Warning>
  You must enable the appropriate feature flag for your broker. If you use a URL scheme without the corresponding feature enabled, you'll get a compile-time error.
</Warning>

## Choosing a broker

<CardGroup cols={1}>
  <Card title="Redis" icon="bolt" href="/brokers/redis">
    **Best for:** General purpose, high throughput, simple setup

    * Fast in-memory storage
    * Simple operational model
    * Good for most use cases
    * Supports fairness queues
  </Card>

  <Card title="RabbitMQ" icon="rabbit" href="/brokers/rabbitmq">
    **Best for:** Complex routing, enterprise messaging

    * Robust message delivery guarantees
    * Advanced routing capabilities
    * Excellent monitoring tools
    * Supports delayed/scheduled messages (with plugin)
  </Card>

  <Card title="SurrealDB" icon="database" href="/brokers/surrealdb">
    **Best for:** When you already use SurrealDB, embedded queues

    * Use your existing database
    * In-memory option for testing
    * Good for embedded scenarios
  </Card>
</CardGroup>

## Feature comparison

| Feature            | Redis | RabbitMQ        | SurrealDB |
| ------------------ | ----- | --------------- | --------- |
| Connection pooling | ✅     | ✅               | ✅         |
| Retry handling     | ✅     | ✅               | ✅         |
| Message scheduling | ✅     | ✅ (with plugin) | ✅         |
| Fairness queues    | ✅     | ❌               | ❌         |
| Management API     | ✅     | ✅               | ❌         |
| In-memory mode     | ❌     | ❌               | ✅         |

## Enabling multiple brokers

You can enable multiple brokers in your project:

```toml theme={null}
[dependencies]
broccoli_queue = { version = "0.4", features = ["redis", "rabbitmq"] }
```

This allows your application to connect to different brokers at runtime:

```rust theme={null}
async fn connect_to_broker(url: &str) -> Result<BroccoliQueue, BroccoliError> {
    BroccoliQueue::builder(url)
        .pool_connections(5)
        .build()
        .await
}

// Connect based on environment
let broker_url = std::env::var("BROKER_URL")?;
let queue = connect_to_broker(&broker_url).await?;
```

## Connection URL formats

<CodeGroup>
  ```text Redis theme={null}
  redis://localhost:6379
  redis://user:password@localhost:6379
  redis://localhost:6379/0  # database number
  rediss://localhost:6379   # TLS
  ```

  ```text RabbitMQ theme={null}
  amqp://localhost:5672
  amqp://user:password@localhost:5672
  amqp://user:password@localhost:5672/vhost
  amqps://localhost:5671   # TLS
  ```

  ```text SurrealDB theme={null}
  ws://localhost:8000
  wss://localhost:8000     # TLS
  mem://                   # in-memory (testing)
  ```
</CodeGroup>

## Broker configuration

All brokers share common configuration through the builder:

```rust theme={null}
let queue = BroccoliQueue::builder("redis://localhost:6379")
    // Connection pool size
    .pool_connections(10)
    
    // Retry configuration
    .failed_message_retry_strategy(
        RetryStrategy::new()
            .with_attempts(5)
            .retry_failed(true)
    )
    
    // Enable scheduling (broker-specific behavior)
    .enable_scheduling(true)
    
    .build()
    .await?;
```

See the individual broker pages for broker-specific options and considerations.
