Prev Next

Integration / ActiveMQ Interview Questions Intermediate

Why do we use persistent messages in ActiveMQ?

Persistent messages are written to the broker's storage (KahaDB, JDBC, etc.) before delivery is confirmed, so a message survives a broker crash or restart. Without persistence, an in-flight message living only in memory is lost the moment the broker goes down.

Persistent delivery costs some throughput because of the disk write, so its use is a deliberate trade-off: pick it for anything you can't afford to lose (payments, orders), and let genuinely disposable data (like a live metrics feed) go non-persistent for maximum speed. ActiveMQ makes this choice per-message via DeliveryMode.PERSISTENT / NON_PERSISTENT, so a single application can mix both depending on how critical each message stream is.

In code, this is set on the MessageProducer via setDeliveryMode(DeliveryMode.PERSISTENT), or per-message on the send call itself, so the same producer can send a mix of critical and disposable messages to different destinations without needing two separate connections. It's worth noting that persistence protects against broker restarts and crashes, but it doesn't by itself guarantee exactly-once delivery to the consumer - a redelivered persistent message can still be processed twice if the consumer's acknowledgment is lost in transit.

What is the trade-off of using persistent messages?
Which delivery mode survives a broker restart?

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...

ActiveMQ Interview Questions Advanced

Comments & Discussions