Skip to main content

Configuration and integration with Apache ActiveMQ

Info

In a cluster, the nodes of Mercury DB (HgDB) 3.0 exchange messages through Apache ActiveMQ: changes of types and definitions, change packages of the Lucene index, wake-ups of the index secretary and heartbeats. This page describes the broker configuration. A ready-to-use sample is the conf/activemq.xml file in the system-config-sample/linux/apache-activemq directory of the installation package, together with a README.md containing the installation steps.

How the nodes communicate​

Messages for all nodes of the cluster are published on Virtual Topics named VirtualTopic.<name>. Every node reads its own queue named Consumer.<node>.VirtualTopic.<name>, where <node> is the value of the mercury.node.name parameter. The broker creates the queue when the node connects to it for the first time.

Thanks to this, a new node does not require any change of the broker configuration or its restart: it is enough to give the node a unique name. (Earlier versions listed every node by name in the broker configuration, so each new node required editing activemq.xml.)

Topic (with the VirtualTopic. prefix)Purpose
mrc-type-case-registry-changeschanges of case and document types
mrc-type-param-registry-changeschanges of type parameters
mrc-pram-definition-registry-changeschanges of parameter definitions
mrc-case-attribute-registry-changeschanges of case attributes
mrc-lucene-document-registry-changeschange packages of the Lucene index for other nodes
mrc-lucene-wakeup-registry-changeswake-up of the index secretary on other nodes
mrc-heartbeat-registry-changesheartbeats: the state of the nodes

The task queues (mrc-case-view-creator, mrc-case-registry-changes, mrc-bpm-task-narrative-changes, mrc-case-last-updated-cleaner) have a single consumer and need no configuration.

Messages sent with the exclusion of the sender (change packages of the index, wake-ups, heartbeats) are also delivered to the queue of the sender. The node skips its own messages in the application. The filter on the broker side (a selector) was rejected on purpose: it would leave the own messages in the queue of the sender, and the selectorAware option would lose the messages for a node that is switched off at the moment.

Configuration of the broker (conf/activemq.xml)​

Virtual Topic rule​

One rule serves all the nodes. Place it after </shutdownHooks> and before </broker>:

<destinationInterceptors>
<virtualDestinationInterceptor>
<virtualDestinations>
<virtualTopic name="VirtualTopic.>" prefix="Consumer.*." selectorAware="false" />
</virtualDestinations>
</virtualDestinationInterceptor>
</destinationInterceptors>

selectorAware="false" makes the broker deliver the message to the queue of every node, also of a node that is not connected at the moment: the message waits for its return. The wildcard in the forwardTo element of compositeQueue (the previous approach) does not work in ActiveMQ 5.16.4 (verified in a test): sending a message ends with a StackOverflowError.

Dead letter queue​

Add a policy for all queues in <policyEntries>:

<policyEntry queue=">">
<deadLetterStrategy>
<sharedDeadLetterStrategy processExpired="false" />
</deadLetterStrategy>
</policyEntry>

Short-lived messages (heartbeats, wake-ups) expire and do not go to ActiveMQ.DLQ. The queue ActiveMQ.DLQ receives the messages that the application is not able to process. After 5 deliveries, a change package of the index that cannot be processed is moved there and removed from the queue of the node, with an ERROR entry in the server log. Review ActiveMQ.DLQ from time to time and clean it.

Persistence and the data source​

In a cluster, the broker keeps its messages in a database (PostgreSQL in the sample), so that a restart does not lose the messages: replace the persistenceAdapter with jdbcPersistenceAdapter and define the postgresql-ds data source after the </broker> tag. The complete example is in the sample activemq.xml and in the README.md next to it. Do not store real passwords in files kept in a repository.

Operation​

Adding a node​

Do not change activemq.xml. Set a unique mercury.node.name on the new node and start the server. The queues Consumer.<node>.VirtualTopic.* appear in the administration console after the first connection of the node.

Retiring a node permanently​

The queues Consumer.<node>.* stay in the broker after the node is switched off. The queue with change packages of the index (Consumer.<node>.VirtualTopic.mrc-lucene-document-registry-changes) does not expire, so for a node that will not come back, delete its Consumer.<node>.* queues in the administration console. Otherwise, the queue will grow.

Migration from the previous configuration​

The earlier configuration with compositeQueue elements listing the nodes (...-node1, ...-node2) cannot be combined with Virtual Topics. Remove it from activemq.xml, restart the broker and deploy the Mercury DB (HgDB) server version with Virtual Topics at the same time, because the old and the new server versions do not cooperate. The queues mrc-*-registry-changes-<node> from the previous configuration are no longer used and can be deleted.

Monitoring​

The state of the queues is visible in the ActiveMQ administration console (by default http://<broker address>:8161/admin). The Mercury DB (HgDB) administration page Data secretaries shows the buffers of the index secretary of the node.