Skip to main content

Overview

Messages in Broccoli are wrapped in a BrokerMessage<T> struct that includes metadata alongside your custom payload.

BrokerMessage structure

Creating message payloads

Your payload type must implement Clone, Serialize, and Deserialize:

Publishing messages

When you publish a message, Broccoli automatically:
  1. Generates a unique task_id
  2. Wraps your payload in a BrokerMessage
  3. Serializes and sends to the broker

Consuming messages

When consuming, you receive the full BrokerMessage:

Message acknowledgment

After processing a message, you must acknowledge or reject it:

Acknowledge (success)

Removes the message from the processing queue:

Reject (failure)

Moves the message to the retry queue or failed queue:
The message will be:
  • Re-queued if attempts < max_retries
  • Moved to failed queue if attempts >= max_retries

Cancel

Remove a message by ID without processing:

Message ordering

Broccoli does not guarantee strict message ordering. Messages may be processed out of order, especially with multiple workers.
If you need ordered processing:
  • Use a single worker (concurrency: Some(1))
  • Or implement ordering logic in your application

Complex payload example