Skip to main content

Overview

SurrealDB can be used as a message broker, which is useful when you already use SurrealDB in your application or need an embedded queue for testing.

Installation

Enable SurrealDB support in your Cargo.toml:

Connection

WebSocket connection

In-memory (testing)

Reuse existing connection

If you already have a SurrealDB connection, you can reuse it:

Starting SurrealDB

Docker

With file persistence

Features

In-memory mode

Perfect for testing and development:

Message scheduling

SurrealDB supports delayed message delivery:

SurrealDB data model

Broccoli stores messages in SurrealDB tables:

Configuration example

Best practices

The mem:// scheme is ideal for unit and integration tests:
If your application already uses SurrealDB, reuse the connection:
SurrealDB may have different concurrency characteristics than dedicated message brokers. Test with your expected load.

Limitations

SurrealDB as a message broker has some limitations compared to Redis or RabbitMQ:
  • No fairness queues - Disambiguator-based fairness is not supported
  • No management API - Queue status monitoring is not available
  • Performance - May not match dedicated brokers for high throughput

When to use SurrealDB

Good use cases:
  • You already use SurrealDB and want to minimize dependencies
  • Testing and development with in-memory queues
  • Embedded applications with moderate queue requirements
Consider Redis or RabbitMQ for:
  • High-throughput production workloads
  • Complex routing requirements
  • When you need fairness queues or management APIs

Troubleshooting

Connection failed

Verify SurrealDB is running:

Concurrency errors

This can occur with parallel consumers. Consider reducing concurrency: