Updated on 2025-07-31 GMT+08:00

Configuring Lazy Queues

By default, messages produced by RabbitMQ producers are stored in the memory. When the memory needs to be released, the messages will be paged out to the disk. Paging takes a long time, during which queues cannot process messages.

If production is too fast (for example during batch processing) or consumers cannot consume messages for a long time due to various reasons (for example when consumers are offline or broke down), a large number of messages will be stacked. Memory usage becomes high and paging is frequently triggered, which may affect message sending and receiving of other queues. In this case, you are advised to use lazy queues.

Lazy queues store as many messages to the disk as possible. Messages are loaded to the memory only when they are being consumed. This reduces memory consumption, but increases I/O and affects single-queue throughput. An important goal of lazy queues is to support long queues, that is, queues with many messages stored or stacked.

Lazy queues are recommended in the following scenarios:

  • Messages may be stacked in queues.
  • There is no high requirement on the queue performance (throughput), for example, less than 10,000 TPS.
  • Stable production and consumption are desired, without being affected by memory changes.

Lazy queues are not suitable in the following scenarios:

  • High RabbitMQ performance is expected.
  • Queues are always short (with no messages stacked).
  • The queue length limit is configured in a policy.

For more information about lazy queues, see Lazy Queues.

Notes and Constraints

Available for RabbitMQ 3.8.35 and later.

Configuring a Lazy Queue

A queue has two modes: default and lazy. The default mode is default.

If these methods are used, the configuration set by the policy takes precedence.

  • Java client: Set the queue in a parameter when calling method channel.queueDeclare.
  • RabbitMQ management UI: Set the queue using a policy.
  • RabbitMQ console: Set the queue when creating a queue.
The following example shows how to set a lazy queue by using channel.queueDeclare on a Java client.
Map<String, Object> args = new HashMap<String, Object>();
args.put("x-queue-mode", "lazy");
channel.queueDeclare("myqueue", false, false, false, args);
  1. Log in to the RabbitMQ management UI.
  2. Click the Admin tab.

    Figure 1 Admin tab page

  3. Choose Policies from the navigation pane.
  4. Add a policy.

    Figure 2 Adding a policy
    Table 1 Policy elements

    Parameter

    Description

    Virtual Host

    Specify the virtual host. The slash (/) indicates the default virtual host.

    Name

    The policy name, which can be customized.

    Pattern

    Regular expression that defines the pattern for matching queues.

    Apply to

    Object to which the policy applies. Select Queues.

    Priority

    A larger value indicates a higher priority.

    Definition

    Configure lazy queues by setting queue-mode=lazy.

  5. Click Add/update policy.

    The following figure shows a successfully added policy.

    Figure 3 Viewing a lazy queue policy

  1. Create a queue by referring to Creating a RabbitMQ Queue and set Lazy Queue to lazy.

    Figure 4 Creating a lazy queue

  2. In the queue list, click View Detail next to the created queue.

    The lazy queue is created when Lazy Queue is lazy.

    Figure 5 Viewing queue details

Related Document

To create a lazy queue by calling an API, see Creating a Queue.