0
0
RabbitMQdevops~5 mins

Flow control mechanism in RabbitMQ - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes, a message broker like RabbitMQ can get overwhelmed if too many messages arrive too fast. The flow control mechanism helps slow down the message producers so the broker can handle messages smoothly without crashing or losing data.
When your RabbitMQ server is running out of memory due to high message rates.
When producers send messages faster than consumers can process them.
When you want to prevent RabbitMQ from dropping messages under heavy load.
When you notice RabbitMQ nodes entering flow control mode to protect stability.
When tuning RabbitMQ performance to balance throughput and reliability.
Commands
Check the current status of the RabbitMQ server including memory and flow control state.
Terminal
rabbitmqctl status
Expected OutputExpected
Status of node rabbit@my-server ... [{pid,12345}, {running_applications,[{rabbit,"RabbitMQ","3.11.14"}, {os_mon,"CPO CXC 138 46","2.4.7"}]}, {memory,[{total,104857600},{connection_readers,1024000},{connection_writers,1024000},{connection_channels,2048000},{connection_other,5120000},{queue_procs,10240000},{other_proc,20480000},{mnesia,1024000},{mgmt_db,1024000},{msg_index,1024000},{other_ets,1024000},{binary,1024000},{code,1024000},{atom,1024000},{other_system,5120000}]}]
Set the memory high watermark to 40% of total RAM to trigger flow control earlier and protect the server.
Terminal
rabbitmqctl set_vm_memory_high_watermark 0.4
Expected OutputExpected
No output (command runs silently)
List all queues with the count of ready and unacknowledged messages to monitor queue backlogs.
Terminal
rabbitmqctl list_queues name messages_ready messages_unacknowledged
Expected OutputExpected
Listing queues ... queue1 10 2 queue2 0 0 queue3 5 1
Apply a policy to limit queue length to 1000 messages to help control flow and prevent memory overload.
Terminal
rabbitmqctl set_policy flow_control "^" '{"max-length":1000}' --apply-to queues
Expected OutputExpected
Setting policy "flow_control" for queues matching "^" ...
--apply-to - Specify the type of resource the policy applies to (queues in this case)
Key Concept

If you remember nothing else from this pattern, remember: flow control in RabbitMQ slows down producers to keep the broker stable under heavy load.

Common Mistakes
Ignoring memory high watermark settings and letting RabbitMQ use all available RAM.
This can cause RabbitMQ to crash or kill processes when memory runs out.
Set a reasonable memory high watermark like 0.4 to trigger flow control before memory is exhausted.
Not monitoring queue lengths and message backlogs.
Queues growing too large indicate consumers are too slow or producers too fast, risking overload.
Regularly check queue stats and apply policies to limit queue sizes.
Applying flow control policies without testing impact on producers.
Producers may block or fail if flow control is too aggressive, causing application issues.
Gradually tune flow control settings and monitor producer behavior.
Summary
Use 'rabbitmqctl status' to check server health and flow control state.
Set memory high watermark to control when flow control triggers.
Monitor queues to detect message backlogs that cause flow control.
Apply policies to limit queue length and protect RabbitMQ stability.