By default RabbitMQ tries to keep your whole queue in memory. This is OK as long as your messages are processed fast enough but not if your queue becomes very long(many millions of messages). Queues can become very long for various reasons:
- consumers are offline / have crashed / are down for maintenance
- there is a sudden message ingress spike, producers are outpacing consumers
- consumers are slower than normal
Lazy Queues can help in these situations- messaged are moved to disk as early as practically possible, and are only loaded in RAM when requested by consumers.This comes at a cost of increased disk I/O.
You can configure this in MassTransit when configuring your receive endpoint:
More information: https://www.rabbitmq.com/lazy-queues.html