Integration / ActiveMQ Interview Questions Intermediate
How is message ordering guaranteed in ActiveMQ?
Within a single Queue with a single active consumer, ActiveMQ preserves the order messages were sent in - FIFO delivery is the default behavior. As soon as multiple consumers listen on the same queue, ActiveMQ load-balances messages across them, so strict global ordering across consumers is no longer guaranteed, only per-consumer ordering of whatever each one happens to receive.
Message priority (JMSPriority) and expiration can also reorder delivery, since a higher-priority or soon-to-expire message can jump ahead. If an application needs strict ordering with multiple parallel workers, a common pattern is to route related messages (for example, the same customer ID) to the same queue, or use message groups, which pin all messages sharing a group ID to one consumer.
It's also worth knowing that ordering guarantees apply only within a single destination; there's no cross-queue or cross-topic ordering promise in ActiveMQ, so an application that needs strict ordering across several related destinations has to build that coordination itself, typically by funnelling related events through one queue via a shared key.
More Related questions...