Starting with 5.3.1, ActiveMQ provides configurable IOException handling for its file-based message stores. From version 5.5 the handler is also invoked when the JDBC persistence adapter gets a failure on
Default IOException handler
ActiveMQ comes with a default IOException handler, which does the following. When some of the file-based message stores encounter IOException it can be one of the two things: either the disk is unavailable of there's no more space on the disk.
The first case is usually encountered when disk fails or network disk is disconnected. These errors are not "recoverable" and we usually want to shutdown the broker until problems with the disk are solved.
When there's no more space on the disk, we usually want to wait that some space is reclaimed and continue what we have been doing before (exchanging messages). All file-based persistent stores are capable of surviving these kind of errors.
Configuring Default IOException handler
There are a couple of properties you can use to tune the behavior of the
DefaultIOExceptionHandler. First, instantiate the exception handler as a bean. Then configure the broker to use the exception handler by setting the broker's
Handler configuration properties:
true all errors are ignored and the broker remains running.
false 'no disk space' errors are treated the same as other errors causing the broker to be stopped.
The string used to match against the exception's message. When matched a 'no disk space' error results.
true all SQLExceptions are ignored by the handler allowing them to be handled by the persistence adapter's locker. When
false the exception handler processes the exception.
The SQLException phrase to match when ignoring SQLExceptions. Only matched exceptions are ignored. All SQLExceptions match the default empty string.
true transport connectors are stopped (client connections are refused), however, the broker will remain running. The transport connectors will be restarted following a successful persistence adapter checkpoint. All exceptions are ignored whilst the transport connectors are stopped. This option ensures that the broker does not need to be manually restarted in the event of a DB restart, for example.
The interval between persistence adapter checkpoints. Typically used in conjunction with
Options in red are available in version 5.5
The default configuration will try to find a specified string in the exception message to determine whether it is a 'no disk space' error. On most platforms (at least those we have tested), you'll find the word 'space' in it. Of course, you can customize this to your platform by using
Note: as of ActiveMQ 5.11 the
JDBCIOExceptionHandler has been deprecated. It has been replaced by the
org.apache.activemq.util.LeaseLockerIOExceptionHandler that will work with any persistence adapter that supports pluggable storage lockers whether or not a locker is in use.
Writing your own handler
In case this handler doesn't work for you, you can write your own. For example you might want to change the way how you detect full disk and execute some external command, like
df on Linux to be sure.
All you have to do is implement the
org.apache.activemq.util.IOExceptionHandler interface then configure the broker to use it: