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

Configuring a Single Active Consumer

A queue can have multiple registered consumers, but single active consumer allows only one consumer to consume messages from the queue. Another consumer can consume messages only when the active one is abnormal. Single active consumer can be used when the message consumption sequence must be ensured and high reliability is required.

In Figure 1, Producer produces nine messages. Due to the setting of single active consumer, only Consumer 1 can consume messages.

For more information about single active consumer, see Single Active Consumer.

Figure 1 Single active consumer

Notes and Constraints

Available for RabbitMQ 3.8.35 and later.

Procedure

A single active consumer can be configured when a queue is declared on a client or on the RabbitMQ management UI.

When declaring a queue, you can configure a single active consumer by setting the x-single-active-consumer parameter to true.

The following example shows how to configure single active consumer on a Java client.
Channel ch = ...;
Map<String, Object> arguments = newHashMap<String, Object>();
arguments.put("x-single-active-consumer", true);
ch.queueDeclare("my-queue", false, false, false, arguments);

  1. Log in to the RabbitMQ management UI.
  2. Click the Queues tab.
  3. Create a single active consumer queue.

    Figure 2 Creating a single active consumer queue
    Table 1 Queue parameters

    Parameter

    Description

    Virtual Host

    Virtual host to which a single active consumer queue belongs. The slash (/) indicates the default virtual host.

    Type

    Queue type.

    Name

    Name of the single active consumer queue, which is user-defined.

    Durability

    Whether to enable persistence.

    • Durable: This queue survives after server restart.
    • Transient: This queue will be deleted after server restart and needs to be recreated.

    Node

    Node where a single active consumer queue is deployed.

    Auto delete

    Whether to enable automatic deletion.

    • Yes: This queue will be automatically deleted when the last consumer unsubscribes from the queue.
    • No: This queue will not be deleted when the last consumer unsubscribes from the queue.

    Arguments

    Set the single active consumer attribute through parameter x-single-active-consumer=true.

  4. Click Add queue.
  5. Check whether the queue features contain single active consumer on the Queues page. As shown in Figure 3, SAC indicates that a single active consumer has been set in the queue.

    Figure 3 Viewing queue features