Configuration
Configure RabbitMQ connection and event routing through environment variables.Connection Settings
.env
The connection URI format is:
amqp://username:password@host:port/vhost- Default port: 5672
- Default vhost:
/ - For RabbitMQ with SSL, use
amqps://protocol
Global vs Instance Events
You can configure RabbitMQ to work in two modes:- Per-Instance Queues
- Global Queues
Each instance gets its own queues and exchange:Creates queues like:
.env
my_instance.messages.upsertmy_instance.qrcode.updatedmy_instance.connection.update
Exchange and Queue Setup
Evolution API automatically creates:1
Topic Exchange
A topic exchange with the configured name (default:
evolution)- Durable: Survives broker restarts
- Type: Topic (enables routing pattern matching)
2
Quorum Queues
Queues for each enabled event:
- Durable: Messages persist to disk
- Type: Quorum (replicated, highly available)
- Auto-delete: Disabled
3
Queue Bindings
Bindings between queues and exchange using routing keys:
- Routing key format: event name (e.g.,
MESSAGES_UPSERT) - Enables selective event consumption
Available Events
Configure which events are sent to RabbitMQ:- Instance Events
- Message Events
- Contact Events
- Chat & Group Events
- Other Events
.env
Per-Instance Configuration
Configure RabbitMQ events for a specific instance via API:Message Format
Messages published to RabbitMQ have the following JSON structure:Consuming Events
Here are examples of consuming events from RabbitMQ:Connection Resilience
Evolution API implements automatic reconnection with exponential backoff:- Initial delay: 5 seconds
- Maximum attempts: 10
- Exponential backoff: Delay doubles each attempt (up to 5 times)
- Heartbeat: 30 seconds to detect connection loss
During connection loss, Evolution API will queue events in memory and retry delivery. Monitor your RabbitMQ connection status in the logs.
Best Practices
1
Use Quorum Queues
Evolution API creates quorum queues by default for high availability and data safety. Ensure your RabbitMQ cluster has at least 3 nodes for optimal quorum queue performance.
2
Enable Acknowledgments
Always acknowledge messages after successful processing to prevent message loss:
3
Handle Processing Errors
Implement error handling and use dead letter queues for failed messages:
4
Set Prefetch Count
Limit concurrent message processing per consumer:
5
Monitor Queue Depth
Set up alerts for queue depth to detect processing bottlenecks.
Troubleshooting
Connection refused
Connection refused
- Verify RabbitMQ is running:
systemctl status rabbitmq-server - Check the connection URI in your
.envfile - Ensure firewall allows port 5672 (or your configured port)
- Verify credentials are correct
Messages not appearing in queues
Messages not appearing in queues
- Check that specific events are enabled in configuration
- Verify
RABBITMQ_ENABLED=true - Check Evolution API logs for RabbitMQ errors
- Ensure the instance is connected to WhatsApp
Consumer not receiving messages
Consumer not receiving messages
- Verify queue binding to exchange
- Check routing key matches event name
- Ensure consumer is acknowledging messages
- Check for messages in dead letter queue
High memory usage
High memory usage
- Check queue depth - consumers may be too slow
- Increase number of consumers
- Optimize message processing code
- Consider increasing
RABBITMQ_FRAME_MAXif messages are large