ActiveMQ stores messages according to delivery guarantees and destination type, with persistent messages written to stable storage and nonpersistent messages handled for speed when durability is not required. Queues use a straightforward FIFO model where each message is delivered to one consumer and removed only after acknowledgment, while topics are treated differently because multiple durable subscribers may need the same message at different times. To avoid unnecessary duplication, the broker keeps one stored copy for a topic and uses subscriber pointers so each durable consumer can retrieve its next message independently.
The chapter then compares the main storage options available in ActiveMQ. KahaDB is the recommended general-purpose store, designed for speed, scalability, and ease of use with file-based logs, indexes, and in-memory caching. The older AMQ store offers similar journal-and-index behavior and can be very fast, but it is less suitable for large numbers of destinations and may recover more slowly after an unclean shutdown. JDBC storage trades raw performance for the convenience of using an existing relational database, including support for shared-database master/slave setups, while the memory store keeps messages only in RAM and is best for lightweight testing or short-lived workloads.
In addition to long-term persistence, ActiveMQ can cache messages in the broker for topic consumers that reconnect later, using subscription recovery policies. These policies let you control whether caching is based on memory size, message count, selectors, expiration time, only the latest message, or no caching at all. This gives ActiveMQ flexible options for real-time or short-lived data streams where full persistence may be unnecessary, balancing retrieval convenience, performance, and storage overhead.
First in, first out message storage for queues
Messages stored for durable subscribers to topics use message pointers.
In KahaDB messages are stored in indexed log files and cached for performance.
The KahaDB message store directory structure
In the AMQ store messages are stored in referenced log files and cached for performance.
The AMQ message store directory structure
FAQ
What is the difference between persistent and nonpersistent messages in ActiveMQ?Persistent messages are written to stable storage so they survive broker restarts and can be delivered later, while nonpersistent messages are not logged to stable storage and are used when speed matters more than guaranteed delivery.How are messages stored differently for queues and topics in ActiveMQ?Queues store messages in first-in, first-out order and delete them only after a consumer acknowledges them. Topics store one copy of a message for durable subscribers, with each subscriber maintaining its own pointer to the next message it should receive.What is KahaDB and why is it recommended in ActiveMQ?KahaDB is ActiveMQ’s recommended general-purpose message store. It is file-based, transactional, fast, scalable, and easy to use because it does not require a third-party database.What are the main parts of the KahaDB message store?KahaDB has three main parts: data logs that store messages in append-only journal files, a cache that temporarily holds messages for active consumers, and BTree indexes that point to messages in the logs and preserve queue order and topic subscriber pointers.What files are found in a typical KahaDB directory?A KahaDB directory typically contains db log files, an optional archive directory, db.data for persistent BTree indexes, and db.redo for recovering indexes after an unclean shutdown.When should the AMQ message store be used instead of KahaDB?The AMQ message store can be a good choice when message throughput is the main goal and the number of persistent destinations is relatively low. It is file-based and fast, but it is less suitable for brokers with thousands of queues because each destination has its own index.What is the JDBC message store used for in ActiveMQ?The JDBC message store is used when you want ActiveMQ to persist messages in a relational database. It is often chosen because an organization already has database expertise or wants to use a shared database for master/slave broker setups.Which tables does the JDBC message store use?The JDBC store uses three tables: ACTIVEMQ_MSGS for message data, ACTIVEMQ_ACKS for durable subscriber tracking and last acknowledged message IDs, and ACTIVEMQ_LOCK to ensure only one broker instance accesses the database at a time.What is the memory message store in ActiveMQ?The memory message store keeps messages in memory instead of writing them to disk. It is useful for small or temporary workloads and for tests, but it requires enough JVM memory and does not provide long-term persistence.How does ActiveMQ cache messages for topic consumers?ActiveMQ caches topic messages in memory using a subscription recovery policy. This is mainly for retroactive, nondurable topic consumers, and policies such as fixed size, fixed count, query-based, timed, last image, and no recovery control what gets cached and for how long.
pro $24.99 per month
access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!