Overview
Broccoli includes built-in retry handling for failed messages. When a message handler returns an error, the message can be automatically re-queued for another attempt.Default behavior
By default, Broccoli:- Enables retries for failed messages
- Allows up to 3 retry attempts
- Moves messages to a failed queue after exhausting retries
Configuring retry strategy
UseRetryStrategy when building your queue:
RetryStrategy options
with_attempts(n)
Set the maximum number of retry attempts:
retry_failed(bool)
Enable or disable retries entirely:
How retries work
Tracking attempts
EachBrokerMessage includes an attempts field:
Custom error handling
For fine-grained control, useprocess_messages_with_handlers:
Best practices
Idempotent handlers
Idempotent handlers
Design your message handlers to be idempotent. Since messages may be retried, the same message could be processed multiple times.
Transient vs permanent failures
Transient vs permanent failures
Consider whether failures are transient (network issues, temporary unavailability) or permanent (invalid data, business rule violations).
Exponential backoff
Exponential backoff
Broccoli doesn’t include built-in backoff, but you can implement it in your handler:
Failed message queue
Messages that exceed the retry limit are moved to a failed queue ({queue_name}:failed). You can:
- Monitor this queue for alerting
- Manually inspect and retry failed messages
- Use the management API to retrieve queue status