<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jon Clarke on Medium]]></title>
        <description><![CDATA[Stories by Jon Clarke on Medium]]></description>
        <link>https://medium.com/@jon.clarke?source=rss-27c6af0e69f6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bIu3DhD0ly_cmFOL3JAYIg.jpeg</url>
            <title>Stories by Jon Clarke on Medium</title>
            <link>https://medium.com/@jon.clarke?source=rss-27c6af0e69f6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 18:20:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jon.clarke/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Multi Data Centre Message Brokers with ActiveMQ]]></title>
            <link>https://medium.com/thg-tech-blog/multi-data-centre-message-brokers-with-activemq-28495046370e?source=rss-27c6af0e69f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/28495046370e</guid>
            <category><![CDATA[message-queue]]></category>
            <category><![CDATA[activemq]]></category>
            <dc:creator><![CDATA[Jon Clarke]]></dc:creator>
            <pubDate>Mon, 12 Nov 2018 08:49:34 GMT</pubDate>
            <atom:updated>2018-11-12T08:49:34.837Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="http://activemq.apache.org/">ActiveMQ</a> is a popular open source broker allowing clients to communicate by exchanging well defined messages. It’s a typical component of a micro services architecture where services need to communicate asynchronously using such messages.</p><p>We’ve used ActiveMQ since version 5.4 and have since migrated to a version supporting <a href="http://activemq.apache.org/virtual-destinations.html">virtual destinations</a>; virtual topics solve a problem of multiple subscribers wishing to consume the same message.</p><p>This article explains how we use ActiveMQ and ultimately how we configured it. There are certainly a few gotchas configuring ActiveMQ and we hope this is of some use.</p><p>An example of how we might use ActiveMQ message broker; our ordering system persists an order placed by a customer and emits a message on a virtual topic to indicate a new order has been created:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*nc_IOD8qRIDc0OYZa_EebA.png" /></figure><p>Any number of systems might be interested in such a message, for instance our warehouse system (to allocate stock), our CRM system (to send an order confirmation email to the customer), reporting systems and so on. Consumer queues may be added dynamically to a virtual topic without broker reconfiguration or restart.</p><h3>ActiveMQ in multiple networks/data centres with improved availability</h3><p>A goal of our ecommerce platform was to extend it across multiple data centres to improve resiliency and availability. This gave us an opportunity to extend our messaging capability to allow for client failures/maintenance/upgrades in a data centre. So, for instance, we could handle the case where our CRM system was down for maintenance in one DC:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yeEZx6GzTzzqCQnPE3v8Kg.png" /></figure><p>Here, a message on a queue cannot be consumed by the CRM email system in DC1, but it can be processed by a consumer on the broker in DC2 as the brokers are networked together. In practice, we don’t care which of the CRM instances handles the message.</p><p>Our use of ActiveMQ had only been in the context of emitting and consuming messages within a single data centre. To share messages between data centres, we took advantage of ActiveMQ’s <a href="http://activemq.apache.org/networks-of-brokers.html">network of brokers</a>, where multiple message brokers can be connected to support distributed queues and topics across a network.</p><p>To enable this, we must have a broker in each data centre, and the brokers must be connected. We installed ActiveMQ in our two data centres, configured the networking options. We spent quite some time optimising this configuration to eliminate some instabilities with the broker network. Here’s the setup we settled on. (Information on downloading and installing ActiveMQ is <a href="http://activemq.apache.org/getting-started.html">here.</a>)</p><h3>Naming brokers</h3><p>The default install of ActiveMQ, the <em>activemq.xml</em> configuration file names the broker “localhost”:</p><pre>&lt;broker xmlns=&quot;http://activemq.apache.org/schema/core&quot; brokerName=&quot;localhost&quot; dataDirectory=&quot;${activemq.data}&quot; /&gt;</pre><p>We’d recommend you rename each broker to reflect its function or location. At the very least this will help to avoid confusion when accessing the ActiveMQ broker UI.</p><p>For example, on broker 1:</p><pre>&lt;broker xmlns=&quot;http://activemq.apache.org/schema/core&quot; brokerName=&quot;amqDC1&quot; dataDirectory=&quot;${activemq.data}&quot; /&gt;</pre><p>Will display in the ActiveMQ UI as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*6XnZkHVEJdbTiOcr8CTRXQ.png" /></figure><h3>Networking the brokers</h3><p>To allow messages to move across a network to a remote consumer, it is possible to connect them together. In a scenario with just two networks, the message brokers can be connected directly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*6OYcmKxqa1iFZ0DsvkHdrg.png" /></figure><p>In the above example, messages are designed to flow in one direction only, with messages produced in broker 1 and consumed by a client connected to broker 2. The <em>networkConnectors</em> element for this configuration in broker 1 might look like:</p><pre>&lt;networkConnectors&gt;<br>    &lt;networkConnector name=&quot;bridge&quot;<br>                    uri=&quot;static:(tcp://dc1-virtualmachine2:61616)&quot;/&gt;<br>&lt;/networkConnectors&gt;</pre><p>Notice we prefer to use static discovery instead of multicast and that we left <em>duplex</em> set to false; this is because we prefer to be explicit with the network connector configuration and anyone looking at the configuration can instantly understand which brokers are connected. We also have control of the network topology instead of all brokers connecting to each other in a graph like configuration.</p><p>We settled on a bunch of other configuration options, so our network connector configuration now looked like:</p><pre>&lt;networkConnectors&gt;<br>    &lt;networkConnector name=&quot;bridge&quot;<br>                      uri=&quot;static:(tcp://dc1-virtualmachine2:61616)&quot;<br>     networkTTL=”2”<br>     dynamicOnly=&quot;true&quot;<br>     decreaseNetworkConsumerPriority=&quot;true&quot;<br>     suppressDuplicateQueueSubscriptions=&quot;true&quot; /&gt;<br>&lt;/networkConnectors&gt;</pre><p>The <em>networkTTL </em>setting indicates messages and subscriptions can pass through 2 brokers in the network. Setting <em>dynamicOnly </em>to true will only forward a message if there is an active consumer on the connected broker. <em>decreaseNetworkConsumerPriority </em>is set so that messages prefer local consumers rather than those on a networked broker (messages can still be despatched to another broker, depending on how busy the local consumer is). Finally, <em>suppressDuplicateQueueSubscriptions </em>is set to eliminate potential duplicate intermediary subscriptions (only possible in more complex broker networks where there are multiple potential routes through the network).</p><p>We also wanted to be selective about which queues we would bridge between the brokers, so we included a configuration to dynamically include destinations:</p><pre>&lt;networkConnectors&gt;<br>    &lt;networkConnector name=&quot;bridge&quot;<br>                      uri=&quot;static:(tcp://dc1-virtualmachine2:61616)&quot;<br>     networkTTL=”2”<br>     dynamicOnly=&quot;true&quot;<br>     decreaseNetworkConsumerPriority=&quot;true&quot;<br>     suppressDuplicateQueueSubscriptions=&quot;true&quot;&gt; <br>        &lt;dynamicallyIncludedDestinations&gt;<br>          &lt;queue physicalName=&quot;Consumer.crmSystem.VirtualTopic.orderSystem.&gt;&quot; /&gt;<br>          &lt;queue physicalName=&quot;Consumer.warehouseSystem.VirtualTopic.orderSystem.&gt;&quot; /&gt;<br>        &lt;/dynamicallyIncludedDestinations&gt;<br>    &lt;/networkConnector&gt;<br>&lt;/networkConnectors&gt;</pre><p><strong>Warning : </strong>if you don’t specify the queues you wish to bridge, both virtual topics and corresponding consumer queues on those topics will be bridged by default. we found emitting a message on a virtual topic could produce duplicate messages on the consumer queues. You can use the following if bridging a virtual topic is still required:</p><pre>&lt;dynamicallyIncludedDestinations&gt;<br>   &lt;topic physicalName=&quot;VirtualTopic.name&quot; /&gt;<br>&lt;/dynamicallyIncludedDestinations&gt;</pre><p>In our scenario, both brokers are producers and consumers, so messages will flow in both directions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*LkgeGxop8oxmo80xE6m0sA.png" /></figure><p>So, the <em>networkConnectors</em> configuration section for these brokers is as follows:</p><p>Broker 1:</p><pre>&lt;networkConnectors&gt;<br>    &lt;networkConnector name=&quot;bridge&quot;<br>                      uri=&quot;static:(tcp://dc1-virtualmachine2:61616)&quot;<br>     networkTTL=”2”<br>     dynamicOnly=&quot;true&quot;<br>     decreaseNetworkConsumerPriority=&quot;true&quot;<br>     suppressDuplicateQueueSubscriptions=&quot;true&quot;&gt;<br>       &lt;dynamicallyIncludedDestinations&gt;<br>           &lt;queue physicalName=&quot;Consumer.crmSystem.VirtualTopic.orderSystem.&gt;&quot; /&gt;<br>           &lt;queue physicalName=&quot;Consumer.warehouseSystem.VirtualTopic.orderSystem.&gt;&quot; /&gt;<br>       &lt;/dynamicallyIncludedDestinations&gt;<br>    &lt;/networkConnector&gt;<br>&lt;/networkConnectors&gt;</pre><p>Broker 2:</p><pre>&lt;networkConnectors&gt;<br>    &lt;networkConnector name=&quot;bridge&quot;<br>                      uri=&quot;static:(tcp://dc2-virtualmachine1:61616)&quot;<br>     networkTTL=”2”<br>     dynamicOnly=&quot;true&quot;<br>     decreaseNetworkConsumerPriority=&quot;true&quot;<br>     suppressDuplicateQueueSubscriptions=&quot;true&quot;&gt; <br>       &lt;dynamicallyIncludedDestinations&gt;<br>          &lt;queue physicalName=&quot;Consumer.crmSystem.VirtualTopic.orderSystem.&gt;&quot; /&gt;<br>          &lt;queue physicalName=&quot;Consumer.warehouseSystem.VirtualTopic.orderSystem.&gt;&quot; /&gt;<br>       &lt;/dynamicallyIncludedDestinations&gt;<br>    &lt;/networkConnector&gt;<br>&lt;/networkConnectors&gt;</pre><p>The chevron &gt;character in the queue names indicates a wild card, <a href="https://access.redhat.com/documentation/en-US/Fuse_ESB_Enterprise/7.1/html/Using_Networks_of_Brokers/files/FMQNetworksDestinationFiltering.html">here</a> is some further information on how to configure destination filters with wildcards.</p><h3>High availability with master slave</h3><p>Whilst we can network several ActiveMQ brokers together, individual brokers are still at risk of failure due to hardware problems etc. So, we also implemented master/slave in each location using a shared file system (we’re using KahaDB for persisting our messages). If an individual master broker fails, the slave can take over, clients re-connect and continue as normal. The master/slave control works on a file lock level so you need a <a href="http://activemq.apache.org/shared-file-system-master-slave.html">file system that can support this</a>.</p><p>So, our connectivity looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P4JNXLALrTNDJhkP_i1Jcw.png" /></figure><p>ActiveMQ supports this arrangement, and the configuration looks as follows:</p><p>DC1 (both master and slave brokers):</p><pre>&lt;networkConnectors&gt;<br>    &lt;networkConnector name=&quot;bridge&quot;<br>                      uri=&quot;masterslave:(tcp://dc2-virtualmachine1:61616,tcp://dc2-virtualmachine2:61616)&quot;<br>     networkTTL=”2”<br>     dynamicOnly=&quot;true&quot;<br>     decreaseNetworkConsumerPriority=&quot;true&quot;<br>     suppressDuplicateQueueSubscriptions=&quot;true&quot;&gt;<br>       &lt;dynamicallyIncludedDestinations&gt;<br>          &lt;queue physicalName=&quot;Consumer.crmSystem.VirtualTopic.orderSystem.&gt;&quot; /&gt;<br>          &lt;queue physicalName=&quot;Consumer.warehouseSystem.VirtualTopic.orderSystem.&gt;&quot; /&gt;<br>       &lt;/dynamicallyIncludedDestinations&gt;<br>    &lt;/networkConnector&gt;<br>&lt;/networkConnectors&gt;</pre><p>DC2 (both master and slave brokers):</p><pre>&lt;networkConnectors&gt;<br>    &lt;networkConnector name=&quot;bridge&quot;<br>                      uri=&quot;masterslave:(tcp://dc1-virtualmachine1:61616,tcp://dc1-virtualmachine2:61616)&quot;<br>     networkTTL=”2”<br>     dynamicOnly=&quot;true&quot;<br>     decreaseNetworkConsumerPriority=&quot;true&quot;<br>     suppressDuplicateQueueSubscriptions=&quot;true&quot;&gt; <br>       &lt;dynamicallyIncludedDestinations&gt;<br>          &lt;queue physicalName=&quot;Consumer.crmSystem.VirtualTopic.orderSystem.&gt;&quot; /&gt;<br>          &lt;queue physicalName=&quot;Consumer.warehouseSystem.VirtualTopic.orderSystem.&gt;&quot; /&gt;<br>       &lt;/dynamicallyIncludedDestinations&gt;<br>    &lt;/networkConnector&gt;<br>&lt;/networkConnectors&gt;</pre><p>Both master and slave brokers cannot be running simultaneously, and you should see the following message in the logs of the slave broker when you start the ActiveMQ process:</p><p><strong>/<em>somesharedfolder</em>/kahadb/lock is locked by another server. This broker is now in slave mode waiting a lock to be acquired | org.apache.activemq.store.SharedFileLocker</strong></p><p>As soon as the master process fails and releases the shared file lock, the slave will take over, becoming the master broker. Restarting the failed instance will cause it to start up in slave mode with the above log message.</p><p>Because master/slave only has one active instance at any one time, we’d recommend that you configure an <a href="http://www.haproxy.org/">HA proxy</a> that will allow you to access the ActiveMQ UI via the proxy. This will save you having to figure out which instance is running as master at any one time.</p><h3>Broker stability</h3><p>Once we had our broker network up and running, and clients connecting successfully, we found that the brokers could be unstable with many bridged queues. Separating the bridged queues into logical groups, under distinct network connectors, solved this issue. For example:</p><pre>&lt;networkConnectors&gt;<br>    &lt;networkConnector name=&quot;bridge-orders&quot;<br>                      uri=&quot;masterslave:(tcp://dc2-virtualmachine1:61616,tcp://dc2-virtualmachine2:61616)&quot;<br>     networkTTL=”2”<br>     dynamicOnly=&quot;true&quot;<br>     decreaseNetworkConsumerPriority=&quot;true&quot;<br>     suppressDuplicateQueueSubscriptions=&quot;true&quot; &gt;<br>    <br>     &lt;dynamicallyIncludedDestinations&gt;<br>        &lt;queue physicalName=&quot;Consumer.crmSystem.VirtualTopic.orderSystem.&gt;&quot; /&gt;<br>      &lt;queue physicalName=&quot;Consumer.warehouseSystem.VirtualTopic.orderSystem.&gt;&quot; /&gt;<br>     &lt;/dynamicallyIncludedDestinations&gt;<br>&lt;/networkConnector&gt;<br>&lt;networkConnector name=&quot;bridge-products&quot;<br>                      uri=&quot;masterslave:(tcp://dc2-virtualmachine1:61616,tcp://dc2-virtualmachine2:61616)&quot;<br>     networkTTL=”2”<br>     dynamicOnly=&quot;true&quot;<br>     decreaseNetworkConsumerPriority=&quot;true&quot;<br>     suppressDuplicateQueueSubscriptions=&quot;true&quot; &gt;<br>    <br>     &lt;dynamicallyIncludedDestinations&gt;<br>        &lt;queue physicalName=&quot;Consumer.systemA.VirtualTopic.orderSystem.&gt;&quot; /&gt;<br>      &lt;queue physicalName=&quot;Consumer.systemB.VirtualTopic.orderSystem.&gt;&quot; /&gt;<br>     &lt;/dynamicallyIncludedDestinations&gt;<br>&lt;/networkConnector&gt;<br>&lt;/networkConnectors&gt;</pre><p>You should expect to see the network connectors in your ActiveMQ UI connections page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*-iR73cY2gfUKL8tmdyvgow.png" /></figure><p><strong>To repeat: don’t bridge all your queues in the same network connectors</strong></p><p>If you need to change your configuration at runtime and don’t want to re-start your broker, there is a <a href="https://activemq.apache.org/runtime-configuration.html">run time plugin</a> you can add in to your configuration. Whilst this does allow you to modify your network connector settings without restarting the broker, we found it didn’t play nicely with an ActiveMQ slave instance so ultimately we’re not using it at the present time.</p><h3>ActiveMQ’s journal files</h3><p>If you are using KahaDB for message persistence, many configuration options are available that affect behaviour. Because our broker is very busy with a high message throughput, unconsumed messages (typically DLQ messages) can cause high storage usage, as ActiveMQ cannot clear its journal files until such messages have been purged or consumed. (<em>Note to devs: ActiveMQ is not there for long term persistence so don’t treat it like a database!</em>).</p><p>Our KahaDB configuration is as follows (further information <a href="http://activemq.apache.org/kahadb.html">here</a>):</p><pre>&lt;persistenceAdapter&gt;<br>       &lt;kahaDB directory=&quot;/somepath/kahadb&quot;<br>           preallocationStrategy=&quot;zeros&quot;<br>           compactAcksIgnoresStoreGrowth=&quot;true&quot;<br>           compactAcksAfterNoGC=&quot;2&quot; /&gt;<br>&lt;/persistenceAdapter&gt;</pre><p>Our KahaDB directory is managed by <a href="https://docs.gluster.org/en/latest/">Gluster</a>; this allows separate virtual machines to share a file system and thus enables the master/slave ActiveMQ file lock behaviour. Note: if you are using Gluster, we found recent versions would consume more and more memory over time, eventually causing problems for ActiveMQ. We’re using Gluster version 3.12.6 which seems to be stable in our environment.</p><p>Other KahaDB settings we experimented with and set accordingly were as follows. <em>preallocationStrategy </em>set to “zeros” improved our throughput; <a href="http://blog.christianposta.com/activemq/speeding-up-activemq-persistent-messaging-performance-by-25x/">here</a> is an article that discusses the subject. <em>compactAcksIgnoresStoreGrowth </em>we have set “true” as it’s rare that our broker is quiet enough that the store isn’t growing — this ensures we can reclaim space in such circumstances. <em>compactAcksAfterNoGC </em>is set low to compact acknowledgements more often.</p><h3>Monitoring and alerting</h3><p>We use Nagios to monitor many aspects of our infrastructure, and it allows us to author custom checks and alerts. There are several aspects of ActiveMQ that we like to monitor, such as:</p><p>- Simple broker health check (is a broker up or down)<br>- Backlog of messages on a queue<br>- DLQ messages<br>- Age of messages on queues with no consumers (typically these are DLQ messages)<br>- Disk usage</p><p>If you’re going to use a master/slave setup, then you will find it simpler to use the HA proxy to your broker to configure automated checks.</p><p>Old messages on DLQs can cause real issues on a busy broker. KahaDB is unable to clean up its journal files and you can find that your persistence storage is consumed very quickly. We’re constantly reminding development teams of the important in monitoring their DLQs and taking action accordingly. You don’t want ActiveMQ getting close to running out of persistence storage; producer flow control will kick in which will have consequences for upstream components emitting messages.</p><p><a href="http://working-with-activemq.blogspot.com/2014/12/finding-old-messages-in-queues.html">This blog post</a> contains a useful Python 2 script that can be used to identify queues with old messages. We adapted this slightly (forgive my far from pretty Python) so that it issues warnings or critical responses depending the age of the oldest message on a queue with no consumers:</p><pre>#!/usr/bin/python</pre><pre>import calendar<br>import sys<br>import time</pre><pre>from xml.dom.minidom import parse,parseString</pre><pre>import urllib2</pre><pre>if len(sys.argv) &lt; 4:<br>    print &quot;run with parameters: activemq_url port (i.e. ui port) warning_secs critical_secs&quot;<br>    sys.exit(0)<br>else:<br>    url_root=sys.argv[1]<br>    port=sys.argv[2]<br>    time_delta_warning=int(sys.argv[3])<br>    time_delta_critical=int(sys.argv[4])<br>url=url_root+&#39;:&#39;+port+&#39;/admin/xml/queues.jsp&#39;<br>try:<br>    dom=parse(urllib2.urlopen(url))<br>except:<br>    print &quot;error pulling queue list, stopping&quot;<br>    sys.exit(3)</pre><pre>queues_msgs={}<br>queues_old_msgs_warning={}<br>queues_old_msgs_critical={}</pre><pre>#find queues with no consumers and at least 1 message<br>for node in dom.getElementsByTagName(&#39;queue&#39;):<br>    con_count= int(node.childNodes[1].getAttribute(&#39;consumerCount&#39;))<br>    queue_size= int(node.childNodes[1].getAttribute(&#39;size&#39;))<br>    queue_name= str(node.getAttribute(&#39;name&#39;))<br>    if queue_size &gt; 0 and con_count &lt; 1 :<br>        queues_msgs[queue_name]=queue_size<br>        #now check each queue for old messages<br>ts = calendar.timegm(time.gmtime()) #get current time<br>#get timestamp for X days ago:<br>delta_warning = time_delta_warning<br>delta_critical = time_delta_critical</pre><pre>ts_old_warning = ts - delta_warning<br>ts_old_critical = ts - delta_critical</pre><pre>oldest_queue_warning = &#39;&#39;<br>oldest_time_str_warning = &#39;&#39;<br>oldest_time_warning = ts_old_warning</pre><pre>oldest_queue_critical = &#39;&#39;<br>oldest_time_str_critical = &#39;&#39;<br>oldest_time_critical = ts_old_warning</pre><pre>for k in queues_msgs.iterkeys():<br>    count_warning = 0<br>    count_critical = 0<br>    url = url_root+&#39;:&#39;+port+&#39;/admin/queueBrowse/&#39;+k+&#39;?view=rss&#39;<br>    try:<br>        queue_dom = parse(urllib2.urlopen(url))<br>        for node in queue_dom.getElementsByTagName(&#39;pubDate&#39;):<br>            time_str = node.childNodes[0].nodeValue<br>            #    example: Tue, 16 Dec 2014 08:30:44 GMT<br>            time_tup = time.strptime(time_str,&#39;%a, %d %b %Y %H:%M:%S %Z&#39;)<br>            time_secs = int(time.mktime(time_tup))<br>            if time_secs &lt; ts_old_warning:<br>                count_warning += 1<br>                queues_old_msgs_warning[k] = count_warning<br>            if time_secs &lt; ts_old_critical:<br>                count_critical += 1<br>                queues_old_msgs_critical[k] = count_critical<br>            if time_secs &lt; oldest_time_warning:<br>                oldest_time_warning = time_secs<br>                oldest_time_str_warning = time_str<br>                oldest_queue_warning = k<br>            if time_secs &lt; oldest_time_critical:<br>                oldest_time_critical = time_secs<br>                oldest_time_str_critical = time_str<br>                oldest_queue_critical = k<br>    except:<br>        print &quot;failed to retrieve all messages for queue:&quot;, k<br>        sys.exit(3)<br>if len(queues_old_msgs_critical) &gt; 0:<br>    print &quot;oldest message (critical) is on queue:&quot;, oldest_queue_critical, &quot;on date/time:&quot;, oldest_time_str_critical<br>    sys.exit(2)<br>elif len(queues_old_msgs_warning) &gt; 0:<br>    print &quot;oldest message (warning) is on queue:&quot;, oldest_queue_warning, &quot;on date/time:&quot;, oldest_time_str_warning<br>    sys.exit(1)<br>else:<br>    sys.exit(0)</pre><p>We can then execute this in a Nagios check as:</p><p>$USER1$/check_activemq_old_messages.py $ARG1$ $ARG2$ $ARG3$ $ARG4$</p><p>The arguments are as follows:</p><p>ARG1 — The URL of the broker UI, e.g. <a href="http://dc1-virtualmachine1/">http://dc1-virtualmachine1</a><br>ARG2 — The port the UI is running on, usually 8161 for ActiveMQ<br>ARG3 — Number of seconds before an unconsumed message triggers a warning response<br>ARG4 — Number of seconds before an unconsumed message triggers a critical response</p><p>Note — we use the HA proxy configured on our brokers in the host URL; no need to reconfigure our alerts if the broker fails over from master to slave. Nagios will then email us about old messages, for example:</p><pre>***** Nagios XI Alert *****</pre><pre>Nagios has detected a problem with this service.</pre><pre>Notification Type: PROBLEM</pre><pre>Service: Old messages<br>Host: dc1-activemqproxy<br>Address: <em>xx.xx.xx.xx</em><br>State: CRITICAL<br>Info:<br>oldest message (critical) is on queue: <em>somequeue</em>.dlq on date/time: Wed, 26 Sep 2018 07:58:44 GMT<br>Date/Time: 2018-09-30 18:45:22</pre><h3>Inspiration and resources</h3><p>Here are some resources that helped us get our network of brokers running.</p><p><a href="http://akuntamukkala.blogspot.com/2014/02/activemq-network-of-brokers-explained.html">http://akuntamukkala.blogspot.com/2014/02/activemq-network-of-brokers-explained.html</a></p><p><a href="http://www.jakubkorab.net/2011/11/understanding-activemq-broker-networks.html">http://www.jakubkorab.net/2011/11/understanding-activemq-broker-networks.html</a></p><p><a href="https://stackoverflow.com/questions/32344317/activemq-5-11-network-of-brokers-and-master-slave-group-config">https://stackoverflow.com/questions/32344317/activemq-5-11-network-of-brokers-and-master-slave-group-config</a></p><p><a href="http://working-with-activemq.blogspot.com/2014/12/finding-old-messages-in-queues.html">http://working-with-activemq.blogspot.com/2014/12/finding-old-messages-in-queues.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28495046370e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thg-tech-blog/multi-data-centre-message-brokers-with-activemq-28495046370e">Multi Data Centre Message Brokers with ActiveMQ</a> was originally published in <a href="https://medium.com/thg-tech-blog">THG Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>