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.
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.
Channel ch = ...; Map<String, Object> arguments = newHashMap<String, Object>(); arguments.put("x-single-active-consumer", true); ch.queueDeclare("my-queue", false, false, false, arguments);
- Log in to the RabbitMQ management UI.
- Click the Queues tab.
- 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.
- Click Add queue.
- 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.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot