Updated on 2023-01-06 GMT+08:00

Single Active Consumer

Scenario

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.

Single active consumer is available only in RabbitMQ 3.8.35.

Figure 1 Single active consumer

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.

Configuration

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 single active consumer.

    Figure 3 Viewing queue features