Search code examples
activemq-classic

Master/Slave non persistent ActiveMQ Classic configuration


I am trying to setup two ActiveMQ Classic brokers used as communication channel for several microservices.

I would like to:

  1. Have the brokers on two different machines so that the two brokers are in failover, where upon switching off one of the machines the other acquires a lock and becomes the master.
  2. Don't have to worry about disk usage that comes with persistent messages.

In short I want to have redundant brokers with no persistence, so I can, for example, switch off one node for mainteinance and have the other accept connections.

It seems there is not way to achieve this as of 5.18.3, since a broker configured to use Kahadb as Shared File System Master Slave but with persistent="false" attribute active produces this log:

WARN | persistent="false", ignoring configured persistenceAdapter: KahaDBPersistenceAdapter

and the brokers effectively ignore the lock file check (they both go active).

The two relavant bits of configuration in settings.xml are:

...
<broker persistent="false" xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}">
...
   <persistenceAdapter>
      <kahaDB directory="/mnt/SHARED_AMQ" lockKeepAlivePeriod="1000">
         <locker>
            <shared-file-locker lockAcquireSleepInterval="1000"/>
         </locker>
      </kahaDB>
   </persistenceAdapter>
...

Mind that I achieved the working redundant configuration with persistence, removing the persistent="false".


Solution

  • To achieve your desired solution, you cannot disable persistence altogether (pesistent="false" should not be used).

    Instead, use the persistence solely for the primary/failover lock (formerly known as master/slave). Clients are responsible for setting the persistence flag, so you will still have non-persistent behavior as desired. Optionally, you can force all messages to be non-persistent using the plugin.

    As a bonus, when you have kahadb enabled, if you start to run out of memory, ActiveMQ will swap non-persistent messages to disk using the temporary store. This allows the broker to handle more non-persistent messages than it has available memory.

    Edit: Please upgrade your ActiveMQ brokers to current releases 6.x or 5.18.x!