<p>I am setting up a cluster of Artemis in Kubernetes with 3 group of master/slave:</p>
<pre><code>activemq-artemis-master-0                               1/1     Running
activemq-artemis-master-1                               1/1     Running
activemq-artemis-master-2                               1/1     Running
activemq-artemis-slave-0                                0/1     Running
activemq-artemis-slave-1                                0/1     Running
activemq-artemis-slave-2                                0/1     Running
</code></pre>
<p>The Artemis version is 2.17.0. Here is my cluster config in master-0 <code>broker.xml</code>. The configs are the same for other brokers except the <code>connector-ref</code> is changed to match the broker:</p>
<pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
&quot;License&quot;); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
&quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
--&gt;
&lt;configuration xmlns=&quot;urn:activemq&quot; xmlns:xi=&quot;http://www.w3.org/2001/XInclude&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;urn:activemq /schema/artemis-configuration.xsd&quot;&gt;
  &lt;core xmlns=&quot;urn:activemq:core&quot; xsi:schemaLocation=&quot;urn:activemq:core &quot;&gt;
    &lt;name&gt;activemq-artemis-master-0&lt;/name&gt;
    &lt;persistence-enabled&gt;true&lt;/persistence-enabled&gt;
    &lt;!-- this could be ASYNCIO, MAPPED, NIO
           ASYNCIO: Linux Libaio
           MAPPED: mmap files
           NIO: Plain Java Files
       --&gt;
    &lt;journal-type&gt;ASYNCIO&lt;/journal-type&gt;
    &lt;paging-directory&gt;data/paging&lt;/paging-directory&gt;
    &lt;bindings-directory&gt;data/bindings&lt;/bindings-directory&gt;
    &lt;journal-directory&gt;data/journal&lt;/journal-directory&gt;
    &lt;large-messages-directory&gt;data/large-messages&lt;/large-messages-directory&gt;
    &lt;journal-datasync&gt;true&lt;/journal-datasync&gt;
    &lt;journal-min-files&gt;2&lt;/journal-min-files&gt;
    &lt;journal-pool-files&gt;10&lt;/journal-pool-files&gt;
    &lt;journal-device-block-size&gt;4096&lt;/journal-device-block-size&gt;
    &lt;journal-file-size&gt;10M&lt;/journal-file-size&gt;
    &lt;!--
       This value was determined through a calculation.
       Your system could perform 1.1 writes per millisecond
       on the current journal configuration.
       That translates as a sync write every 911999 nanoseconds.

       Note: If you specify 0 the system will perform writes directly to the disk.
             We recommend this to be 0 if you are using journalType=MAPPED and journal-datasync=false.
      --&gt;
    &lt;journal-buffer-timeout&gt;100000&lt;/journal-buffer-timeout&gt;
    &lt;!--
        When using ASYNCIO, this will determine the writing queue depth for libaio.
       --&gt;
    &lt;journal-max-io&gt;4096&lt;/journal-max-io&gt;
    &lt;!--
        You can verify the network health of a particular NIC by specifying the &lt;network-check-NIC&gt; element.
         &lt;network-check-NIC&gt;theNicName&lt;/network-check-NIC&gt;
        --&gt;
    &lt;!--
        Use this to use an HTTP server to validate the network
         &lt;network-check-URL-list&gt;http://www.apache.org&lt;/network-check-URL-list&gt; --&gt;
    &lt;!-- &lt;network-check-period&gt;10000&lt;/network-check-period&gt; --&gt;
    &lt;!-- &lt;network-check-timeout&gt;1000&lt;/network-check-timeout&gt; --&gt;
    &lt;!-- this is a comma separated list, no spaces, just DNS or IPs
           it should accept IPV6

           Warning: Make sure you understand your network topology as this is meant to validate if your network is valid.
                    Using IPs that could eventually disappear or be partially visible may defeat the purpose.
                    You can use a list of multiple IPs, and if any successful ping will make the server OK to continue running --&gt;
    &lt;!-- &lt;network-check-list&gt;10.0.0.1&lt;/network-check-list&gt; --&gt;
    &lt;!-- use this to customize the ping used for ipv4 addresses --&gt;
    &lt;!-- &lt;network-check-ping-command&gt;ping -c 1 -t %d %s&lt;/network-check-ping-command&gt; --&gt;
    &lt;!-- use this to customize the ping used for ipv6 addresses --&gt;
    &lt;!-- &lt;network-check-ping6-command&gt;ping6 -c 1 %2$s&lt;/network-check-ping6-command&gt; --&gt;
    &lt;!-- how often we are looking for how many bytes are being used on the disk in ms --&gt;
    &lt;disk-scan-period&gt;5000&lt;/disk-scan-period&gt;
    &lt;!-- once the disk hits this limit the system will block, or close the connection in certain protocols
           that won't support flow control. --&gt;
    &lt;max-disk-usage&gt;90&lt;/max-disk-usage&gt;
    &lt;!-- should the broker detect dead locks and other issues --&gt;
    &lt;critical-analyzer&gt;true&lt;/critical-analyzer&gt;
    &lt;critical-analyzer-timeout&gt;120000&lt;/critical-analyzer-timeout&gt;
    &lt;critical-analyzer-check-period&gt;60000&lt;/critical-analyzer-check-period&gt;
    &lt;critical-analyzer-policy&gt;HALT&lt;/critical-analyzer-policy&gt;
    &lt;page-sync-timeout&gt;2244000&lt;/page-sync-timeout&gt;
    &lt;!-- the system will enter into page mode once you hit this limit.
           This is an estimate in bytes of how much the messages are using in memory

            The system will use half of the available memory (-Xmx) by default for the global-max-size.
            You may specify a different value here if you need to customize it to your needs.

            &lt;global-max-size&gt;100Mb&lt;/global-max-size&gt;

      --&gt;
    &lt;acceptors&gt;
      &lt;!-- useEpoll means: it will use Netty epoll if you are on a system (Linux) that supports it --&gt;
      &lt;!-- amqpCredits: The number of credits sent to AMQP producers --&gt;
      &lt;!-- amqpLowCredits: The server will send the # credits specified at amqpCredits at this low mark --&gt;
      &lt;!-- amqpDuplicateDetection: If you are not using duplicate detection, set this to false
                                      as duplicate detection requires applicationProperties to be parsed on the server. --&gt;
      &lt;!-- amqpMinLargeMessageSize: Determines how many bytes are considered large, so we start using files to hold their data.
                                       default: 102400, -1 would mean to disable large mesasge control --&gt;
      &lt;!-- Note: If an acceptor needs to be compatible with HornetQ and/or Artemis 1.x clients add
                    &quot;anycastPrefix=jms.queue.;multicastPrefix=jms.topic.&quot; to the acceptor url.
                    See https://issues.apache.org/jira/browse/ARTEMIS-1644 for more information. --&gt;
      &lt;!-- Acceptor for every supported protocol --&gt;
      &lt;acceptor name=&quot;artemis&quot;&gt;tcp://0.0.0.0:61616?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;amqpMinLargeMessageSize=102400;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT,OPENWIRE;useEpoll=true;amqpCredits=1000;amqpLowCredits=300;amqpDuplicateDetection=true&lt;/acceptor&gt;
      &lt;!-- AMQP Acceptor.  Listens on default AMQP port for AMQP traffic.--&gt;
      &lt;acceptor name=&quot;amqp&quot;&gt;tcp://0.0.0.0:5672?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=AMQP;useEpoll=true;amqpCredits=1000;amqpLowCredits=300;amqpMinLargeMessageSize=102400;amqpDuplicateDetection=true&lt;/acceptor&gt;
      &lt;!-- STOMP Acceptor. --&gt;
      &lt;acceptor name=&quot;stomp&quot;&gt;tcp://0.0.0.0:61613?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=STOMP;useEpoll=true&lt;/acceptor&gt;
      &lt;!-- HornetQ Compatibility Acceptor.  Enables HornetQ Core and STOMP for legacy HornetQ clients. --&gt;
      &lt;acceptor name=&quot;hornetq&quot;&gt;tcp://0.0.0.0:5445?anycastPrefix=jms.queue.;multicastPrefix=jms.topic.;protocols=HORNETQ,STOMP;useEpoll=true&lt;/acceptor&gt;
      &lt;!-- MQTT Acceptor --&gt;
      &lt;acceptor name=&quot;mqtt&quot;&gt;tcp://0.0.0.0:1883?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=MQTT;useEpoll=true&lt;/acceptor&gt;
    &lt;/acceptors&gt;
    &lt;security-settings&gt;
      &lt;security-setting match=&quot;#&quot;&gt;
        &lt;permission type=&quot;createNonDurableQueue&quot; roles=&quot;amq&quot;/&gt;
        &lt;permission type=&quot;deleteNonDurableQueue&quot; roles=&quot;amq&quot;/&gt;
        &lt;permission type=&quot;createDurableQueue&quot; roles=&quot;amq&quot;/&gt;
        &lt;permission type=&quot;deleteDurableQueue&quot; roles=&quot;amq&quot;/&gt;
        &lt;permission type=&quot;createAddress&quot; roles=&quot;amq&quot;/&gt;
        &lt;permission type=&quot;deleteAddress&quot; roles=&quot;amq&quot;/&gt;
        &lt;permission type=&quot;consume&quot; roles=&quot;amq&quot;/&gt;
        &lt;permission type=&quot;browse&quot; roles=&quot;amq&quot;/&gt;
        &lt;permission type=&quot;send&quot; roles=&quot;amq&quot;/&gt;
        &lt;!-- we need this otherwise ./artemis data imp wouldn't work --&gt;
        &lt;permission type=&quot;manage&quot; roles=&quot;amq&quot;/&gt;
      &lt;/security-setting&gt;
    &lt;/security-settings&gt;
    &lt;address-settings&gt;
      &lt;!-- if you define auto-create on certain queues, management has to be auto-create --&gt;
      &lt;address-setting match=&quot;activemq.management#&quot;&gt;
        &lt;dead-letter-address&gt;DLQ&lt;/dead-letter-address&gt;
        &lt;expiry-address&gt;ExpiryQueue&lt;/expiry-address&gt;
        &lt;redelivery-delay&gt;0&lt;/redelivery-delay&gt;
        &lt;!-- with -1 only the global-max-size is in use for limiting --&gt;
        &lt;max-size-bytes&gt;-1&lt;/max-size-bytes&gt;
        &lt;message-counter-history-day-limit&gt;10&lt;/message-counter-history-day-limit&gt;
        &lt;address-full-policy&gt;PAGE&lt;/address-full-policy&gt;
        &lt;auto-create-queues&gt;true&lt;/auto-create-queues&gt;
        &lt;auto-create-addresses&gt;true&lt;/auto-create-addresses&gt;
        &lt;auto-create-jms-queues&gt;true&lt;/auto-create-jms-queues&gt;
        &lt;auto-create-jms-topics&gt;true&lt;/auto-create-jms-topics&gt;
      &lt;/address-setting&gt;
      &lt;!--default for catch all--&gt;
      &lt;address-setting match=&quot;#&quot;&gt;
        &lt;dead-letter-address&gt;DLQ&lt;/dead-letter-address&gt;
        &lt;expiry-address&gt;ExpiryQueue&lt;/expiry-address&gt;
        &lt;redelivery-delay&gt;0&lt;/redelivery-delay&gt;
        &lt;!-- with -1 only the global-max-size is in use for limiting --&gt;
        &lt;max-size-bytes&gt;-1&lt;/max-size-bytes&gt;
        &lt;message-counter-history-day-limit&gt;10&lt;/message-counter-history-day-limit&gt;
        &lt;address-full-policy&gt;PAGE&lt;/address-full-policy&gt;
        &lt;auto-create-queues&gt;true&lt;/auto-create-queues&gt;
        &lt;auto-create-addresses&gt;true&lt;/auto-create-addresses&gt;
        &lt;auto-create-jms-queues&gt;true&lt;/auto-create-jms-queues&gt;
        &lt;auto-create-jms-topics&gt;true&lt;/auto-create-jms-topics&gt;
      &lt;/address-setting&gt;
    &lt;/address-settings&gt;
    &lt;addresses&gt;
      &lt;address name=&quot;DLQ&quot;&gt;
        &lt;anycast&gt;
          &lt;queue name=&quot;DLQ&quot;/&gt;
        &lt;/anycast&gt;
      &lt;/address&gt;
      &lt;address name=&quot;ExpiryQueue&quot;&gt;
        &lt;anycast&gt;
          &lt;queue name=&quot;ExpiryQueue&quot;/&gt;
        &lt;/anycast&gt;
      &lt;/address&gt;
    &lt;/addresses&gt;
    &lt;!-- Uncomment the following if you want to use the Standard LoggingActiveMQServerPlugin pluging to log in events
      &lt;broker-plugins&gt;
         &lt;broker-plugin class-name=&quot;org.apache.activemq.artemis.core.server.plugin.impl.LoggingActiveMQServerPlugin&quot;&gt;
            &lt;property key=&quot;LOG_ALL_EVENTS&quot; value=&quot;true&quot;/&gt;
            &lt;property key=&quot;LOG_CONNECTION_EVENTS&quot; value=&quot;true&quot;/&gt;
            &lt;property key=&quot;LOG_SESSION_EVENTS&quot; value=&quot;true&quot;/&gt;
            &lt;property key=&quot;LOG_CONSUMER_EVENTS&quot; value=&quot;true&quot;/&gt;
            &lt;property key=&quot;LOG_DELIVERING_EVENTS&quot; value=&quot;true&quot;/&gt;
            &lt;property key=&quot;LOG_SENDING_EVENTS&quot; value=&quot;true&quot;/&gt;
            &lt;property key=&quot;LOG_INTERNAL_EVENTS&quot; value=&quot;true&quot;/&gt;
         &lt;/broker-plugin&gt;
      &lt;/broker-plugins&gt;
      --&gt;
    &lt;cluster-user&gt;clusterUser&lt;/cluster-user&gt;
    &lt;cluster-password&gt;aShortclusterPassword&lt;/cluster-password&gt;
    &lt;connectors&gt;
      &lt;connector name=&quot;activemq-artemis-master-0&quot;&gt;tcp://activemq-artemis-master-0.activemq-artemis-master.svc.cluster.local:61616&lt;/connector&gt;
      &lt;connector name=&quot;activemq-artemis-slave-0&quot;&gt;tcp://activemq-artemis-slave-0.activemq-artemis-slave.svc.cluster.local:61616&lt;/connector&gt;
      &lt;connector name=&quot;activemq-artemis-master-1&quot;&gt;tcp://activemq-artemis-master-1.activemq-artemis-master.svc.cluster.local:61616&lt;/connector&gt;
      &lt;connector name=&quot;activemq-artemis-slave-1&quot;&gt;tcp://activemq-artemis-slave-1.activemq-artemis-slave.svc.cluster.local:61616&lt;/connector&gt;
      &lt;connector name=&quot;activemq-artemis-master-2&quot;&gt;tcp://activemq-artemis-master-2.activemq-artemis-master.svc.cluster.local:61616&lt;/connector&gt;
      &lt;connector name=&quot;activemq-artemis-slave-2&quot;&gt;tcp://activemq-artemis-slave-2.activemq-artemis-slave.svc.cluster.local:61616&lt;/connector&gt;
    &lt;/connectors&gt;
    &lt;cluster-connections&gt;
      &lt;cluster-connection name=&quot;activemq-artemis&quot;&gt;
        &lt;connector-ref&gt;activemq-artemis-master-0&lt;/connector-ref&gt;
        &lt;retry-interval&gt;500&lt;/retry-interval&gt;
        &lt;retry-interval-multiplier&gt;1.1&lt;/retry-interval-multiplier&gt;
        &lt;max-retry-interval&gt;5000&lt;/max-retry-interval&gt;
        &lt;initial-connect-attempts&gt;-1&lt;/initial-connect-attempts&gt;
        &lt;reconnect-attempts&gt;-1&lt;/reconnect-attempts&gt;
        &lt;message-load-balancing&gt;ON_DEMAND&lt;/message-load-balancing&gt;
        &lt;max-hops&gt;1&lt;/max-hops&gt;
        &lt;!-- scale-down&gt;true&lt;/scale-down --&gt;
        &lt;static-connectors&gt;
          &lt;connector-ref&gt;activemq-artemis-master-0&lt;/connector-ref&gt;
          &lt;connector-ref&gt;activemq-artemis-slave-0&lt;/connector-ref&gt;
          &lt;connector-ref&gt;activemq-artemis-master-1&lt;/connector-ref&gt;
          &lt;connector-ref&gt;activemq-artemis-slave-1&lt;/connector-ref&gt;
          &lt;connector-ref&gt;activemq-artemis-master-2&lt;/connector-ref&gt;
          &lt;connector-ref&gt;activemq-artemis-slave-2&lt;/connector-ref&gt;
        &lt;/static-connectors&gt;
      &lt;/cluster-connection&gt;
    &lt;/cluster-connections&gt;
    &lt;ha-policy&gt;
      &lt;replication&gt;
        &lt;master&gt;
          &lt;group-name&gt;activemq-artemis-0&lt;/group-name&gt;
          &lt;quorum-vote-wait&gt;12&lt;/quorum-vote-wait&gt;
          &lt;vote-on-replication-failure&gt;true&lt;/vote-on-replication-failure&gt;
          &lt;!--we need this for auto failback--&gt;
          &lt;check-for-live-server&gt;true&lt;/check-for-live-server&gt;
        &lt;/master&gt;
      &lt;/replication&gt;
    &lt;/ha-policy&gt;
  &lt;/core&gt;
  &lt;core xmlns=&quot;urn:activemq:core&quot;&gt;
    &lt;jmx-management-enabled&gt;true&lt;/jmx-management-enabled&gt;
  &lt;/core&gt;
&lt;/configuration&gt;
</code></pre>
<p>My consumer is defined as a <code>JmsListener</code> in a Spring Boot app. During the consumption of the messages in a queue, the Spring Boot app crashed which results in kubernetes deleting the pod and recreating a new one. However, I noticed that the new pod did not connect to the same Artemis node, thus the left over messages from the previous connection were never consumed.</p>
<p>I thought the whole point of using the cluster is to have all the Artemis nodes act as one unit to deliver messages to the consumer regardless of which node it connect to. Am I wrong? If the cluster cannot reroute the consumer connection to the correct node (which holds the left over messages from previous consumer) then what is the recommended way to deal with this situation?</p>

lnthai2002
<p>First, it's important to note that there's no feature to make a client reconnect to the broker from which it disconnected after the client crashes/restarts. Generally speaking the client shouldn't really care about what broker it connects to; that's one of the main goals of horizontal scalability.</p>
<p>It's also worth noting that if the number of messages on the brokers and the number of connected clients is low enough that this condition arises frequently that almost certainly means you have too many brokers in your cluster.</p>
<p>That said, I believe the reason that your client isn't getting the messages it expects is because you're using the default <code>redistribution-delay</code> (i.e. <code>-1</code>) which means messages will <em>not</em> be redistributed to other nodes in the cluster. If you want to enable redistribution (which is seems like you do) then you should set it to &gt;= 0, e.g.:</p>
<pre class="lang-xml prettyprint-override"><code>      &lt;address-setting match=&quot;#&quot;&gt;
        ...
        &lt;redistribution-delay&gt;0&lt;/redistribution-delay&gt;
        ...
      &lt;/address-setting&gt;
</code></pre>
<p>You can read more about redistribution in <a href="https://activemq.apache.org/components/artemis/documentation/latest/clusters.html#message-redistribution" rel="nofollow noreferrer">the documentation</a>.</p>
<hr />
<p>Aside from that you may want to reconsider your topology in general. Typically if you're in a cloud-like environment (e.g. one using Kubernetes) where the infrastructure itself will restart failed pods then you wouldn't use a master/slave configuration. You'd simply mount the journal on a separate pod (e.g. using NFSv4) such that when a node fails it would be restarted and then reconnect back to its persistent storage. This effectively provides broker high availability (which is what master/slave is designed for outside of cloud environments).</p>
<p>Also, a single instance of ActiveMQ Artemis can handle millions of messages per second depending on the use-case so you may not actually need 3 live nodes for your expected load.</p>
<p>Note, these are general recommendations about your overall architecture and are not directly related to your question.</p>
