Prev Next

Integration / ActiveMQ Interview Questions Advanced

Explain the internal working of producer flow control in ActiveMQ?

Every destination in ActiveMQ has a configured memory limit representing how much of the broker's memory budget that destination's unconsumed messages may occupy. As messages accumulate on a destination, typically because consumers aren't keeping pace, the broker tracks the destination's current memory usage against that limit.

When usage crosses the limit and producer flow control is enabled (the default), the broker doesn't reject the next send outright. Instead it withholds the acknowledgment for the producer's send() call, which causes the client-side send, in synchronous mode, to block inside the API call until the broker signals that memory has freed up again, typically because a consumer processed and acknowledged enough messages to drop usage below the threshold. This pushes back-pressure all the way to the producer thread itself, throttling how fast new messages can enter the system, rather than letting the broker's memory grow unbounded and eventually crash with an OutOfMemoryError.

If a producer can't tolerate blocking, it can enable useAsyncSend or configure a sendTimeout, after which a blocked send throws a ResourceAllocationException instead of blocking indefinitely, giving the application a chance to handle the back-pressure explicitly rather than stalling.

It's worth distinguishing this destination-level memory limit from the broker's overall system usage limit, configured separately - a single busy destination can trigger its own flow control well before the broker as a whole is anywhere near its total memory ceiling, and conversely a broker approaching its global memory limit can apply flow control across many destinations simultaneously even if no single one has individually crossed its own limit. Getting these two limits sized appropriately relative to each other, and relative to the JVM heap, is a common source of tuning work on busy production brokers.

What triggers producer flow control's blocking behavior?
How can a producer avoid blocking indefinitely under flow control?

Invest now in Acorns!!! 🚀 Join Acorns and get your $5 bonus!
Acorns Logo

Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!

Earn passively and while sleeping

Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.

Robinhood Logo

Invest now!!! Get Free equity stock (US, UK only)!

Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.

The Robinhood app makes it easy to trade stocks, crypto and more.


Webull Logo

Webull! Receive free stock by signing up using the link: Webull signup.

More Related questions...

Show more question and Answers...

Cloud

Comments & Discussions