Integration / ActiveMQ Interview Questions Advanced
Explain the lifecycle of a message from producer to consumer in ActiveMQ?
A message travels through several distinct stages between the moment a producer creates it and the moment a consumer finishes with it.
First, the producer creates the message via the Session and calls send(), setting delivery mode, priority, and time-to-live. The broker receives it over a transport connector; if the delivery mode is persistent, it writes the message to KahaDB before the send is considered durable. The broker then enqueues the message on the destination's internal structure and dispatches it to a waiting consumer, respecting that consumer's prefetch limit and the message's priority. The consumer receives it either synchronously via receive() or asynchronously via a MessageListener, processes it, then acknowledges it according to the session's ack mode. On acknowledgment, the broker removes the message from its store; if no acknowledgment ever arrives, the redelivery policy kicks in and, after enough attempts, routes the message to the Dead Letter Queue instead.
Two details matter for correctness along this path. First, if the producer uses persistent delivery with the default synchronous send, the broker doesn't confirm the send back to the producer until the write to KahaDB has actually completed, so a producer that gets a successful response can trust the message won't vanish on a crash moments later. Second, the consumer's prefetch buffer means several messages may already be sitting client-side, dispatched but unacknowledged, before any single one is processed - which is why a consumer crash can leave multiple in-flight messages needing redelivery, not just the one currently being handled when it died.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
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.
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! Receive free stock by signing up using the link: Webull signup.
More Related questions...
