Chapter 12. Paging Messages
AMQ Broker transparently supports huge queues containing millions of messages while the server is running with limited memory.
In such a situation it’s not possible to store all of the queues in memory at any one time, so AMQ Broker transparently pages messages into and out of memory as they are needed, thus allowing massive queues with a low memory footprint.
Paging is done individually per address. AMQ Broker will start paging messages to disk when the size of all messages in memory for an address exceeds a configured maximum size. For more information about addresses, see Addresses, Queues, and Topics.
By default, AMQ Broker does not page messages. You must explicitly configure paging to enable it.
paging example located under
INSTALL_DIR/examples/standard/ for a working example showing how to use paging with AMQ Broker.
12.1. About Page Files
Messages are stored per address on the file system. Each address has an individual folder where messages are stored in multiple files (page files). Each file will contain messages up to a max configured size (
page-size-bytes). The system will navigate on the files as needed, and it will remove the page file as soon as all the messages are acknowledged up to that point.
Browsers will read through the page-cursor system.
Consumers with selectors will also navigate through the page-files and ignore messages that don’t match the criteria.
When you have a queue, and consumers filtering the queue with a very restrictive selector you may get into a situation where you won’t be able to read more data from paging until you consume messages from the queue.
Example: in one consumer you make a selector as 'color="red"' but you only have one color red one million messages after blue, you won’t be able to consume red until you consume blue ones. This is different to browsing as we will "browse" the entire queue looking for messages and while we "depage" messages while feeding the queue.
12.2. Configuring the Paging Directory Location
To configure the location of the paging directory, add the
paging-directory configuration element to the broker’s main configuration file
BROKER_INSTANCE_DIR/etc/broker.xml, as in the example below.
<configuration ...> ... <core ...> <paging-directory>/somewhere/paging-directory</paging-directory> ... </core> </configuration>
AMQ Broker will create one directory for each address being paged under the configured location.
12.3. Configuring an Address for Paging
Configuration for paging is done at the address level by adding elements to a specific
address-settings, as in the example below.
<address-settings> <address-setting match="jms.paged.queue"> <max-size-bytes>104857600</max-size-bytes> <page-size-bytes>10485760</page-size-bytes> <address-full-policy>PAGE</address-full-policy> </address-setting> </address-settings>
In the example above, when messages sent to the address
104857600 bytes in memory, the broker will begin paging.
Paging is done individually per address. If you specify
max-size-bytes for an address, each matching address does not exceed the maximum size that you specified. It DOES NOT mean that the total overall size of all matching addresses is limited to
This is the list of available parameters on the address settings.
Table 12.1. Paging Configuration Elements
The maximum size in memory allowed for the address before the broker enters page mode.
The size of each page file used on the paging system.
10MiB (10 \* 1024 \* 1024 bytes)
Valid values are
The system will keep up to this number of page files in memory to optimize IO during paging navigation.
12.4. How to Drop Messages
Instead of paging messages when the max size is reached, an address can also be configured to just drop messages when the address is full.
To do this just set the
DROP in the address settings
12.4.1. Dropping Messages and Throwing an Exception to Producers
Instead of paging messages when the max size is reached, an address can also be configured to drop messages and also throw an exception on the client-side when the address is full.
To do this just set the
FAIL in the address settings
12.5. How to Block Producers
Instead of paging messages when the max size is reached, an address can also be configured to block producers from sending further messages when the address is full, thus preventing the memory from being exhausted on the server.
Blocking works only if the protocol being used supports it. For example, an AMQP producer will understand a Block packet when it is sent by the broker, but a STOMP producer will not.
When memory is freed up on the server, producers will automatically unblock and be able to continue sending.
To do this just set the
BLOCK in the address settings.
In the default configuration, all addresses are configured to block producers after 10 MiB of data are in the address.
12.6. Caution with Addresses with Multicast Queues
When a message is routed to an address that has multicast queues bound to it, for example, a JMS subscription in a Topic, there is only one copy of the message in memory. Each queue handles only a reference to it. Because of this the memory is only freed up after all queues referencing the message have delivered it.
If you have a single lazy subscription, the entire address will suffer IO performance hit as all the queues will have messages being sent through an extra storage on the paging system.
- An address has 10 queues
- One of the queues does not deliver its messages (maybe because of a slow consumer).
- Messages continually arrive at the address and paging is started.
- The other 9 queues are empty even though messages have been sent.
In this example, all the other 9 queues will be consuming messages from the page system. This may cause performance issues if this is an undesirable state.