Updated on 2024-11-27 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.

Only available in RabbitMQ 3.8.35.

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

Configuring a Single Active Consumer

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);
  • The following example shows how to configure single active consumer on the RabbitMQ management UI.
    Figure 2 Configuring single active consumer

    After the setting is complete, 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