Bootstrap FreeKB - RabbitMQ - Understanding lazy queues
RabbitMQ - Understanding lazy queues

Updated:   |  RabbitMQ articles

Setting a queue as a lazy queue will make it so that messages in the queue are stored on disk, in the Mnesia database instead of in memory. The x-queue-mode argument is used to set a queue as a lazy queue. For example, here is how you would create a queue name lazy.queue, setting the queue as a lazy queue using the rabbitmqadmin declare queue command.

rabbitmqadmin declare queue --vhost=foo name=lazy.queue durable=true arguments='{"x-queue-mode":"lazy"}'

 

And here is how you would set the queue as a lazy queue using the RabbitMQ REST API.

curl
--request PUT
--user john.doe:itsasecret
--url http://hostname:15671/api/queues/foo/a.queue
--header 'content-type: application/json'
--data '{ "auto_delete": false, "durable": true, "arguments": { "x-queue-type": "classic", "x-queue-mode": "lazy" } }'
--write-out "%{http_code}"

 

The rabbitmqctl list_queues command with the message_bytes_ram option can be used to show the amount of memory (RAM) being used by the queue.

Let's say you have two queues, a non-lazy and a lazy queue. Notice that both queues contain 100 messages, but with the lazy queue, 0 bytes of RAM are being used since the messages are stored on disk, in the Mnesia database.

~]# rabbitmqctl list_queues --vhost foo name messages message_bytes_ram arguments
name           messages  message_bytes_ram       arguments
nonlazy.queue  100       90318                   []
lazy.queue     100       0                       [{"x-queue-mode","lazy"}]

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 1bbf10 in the box below so that we can be sure you are a human.