<!--
    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 "License"); 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 "AS IS" 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.
-->
<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:amq="http://activemq.apache.org/schema/core"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

    <!-- Allows us to use system properties as variables in this configuration file -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />

    <!--
        The <broker> element is used to configure the ActiveMQ broker.

        advisories incurr a hit with every add connection|destination|producer|consumer
          - client side:  providerUrl = tcp://localhost:61616?jms.watchTopicAdvisories=false
        statistics have a small impact on concurrency so disable
        schedualer has a small impact as it checks for the presence three properties on each message
        jmx adds a bunch of wrapper classes

        ACTIVEMQ_OPTS_MEMORY="-Xmx11g -Xms6g -Dorg.apache.activemq.UseDedicatedTaskRunner=false -Djava.util.logging.config.file=logging.properties -XX:+UseLargePages"
    -->
    <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost"
        dataDirectory="${activemq.data}" deleteAllMessagesOnStartup="true"
        advisorySupport="false"
        enableStatistics="false"
        schedulerSupport="false"
        useJmx="false">

        <destinationPolicy>
            <policyMap>
              <policyEntries>
                <!--
                    producerFlowControll thread unnecessary with no memory limits
                    with no failover, no need to suppress duplicates so audit can be disabled
                    message expiry thread unnecessary as normal dispatch will handle expiry
                -->
                <policyEntry topic=">" producerFlowControl="false" enableAudit="false" expireMessagesPeriod="0">
                  <pendingSubscriberPolicy>
                    <!-- keep all references in memory -->
                    <vmCursor />
                  </pendingSubscriberPolicy>
                </policyEntry>
                <policyEntry queue=">" producerFlowControl="false" enableAudit="false" expireMessagesPeriod="0">
                  <pendingQueuePolicy>
                    <!-- keep all references in memory -->
                    <vmQueueCursor/>
                  </pendingQueuePolicy>

                </policyEntry>
              </policyEntries>
            </policyMap>
        </destinationPolicy>


        <!--
            The managementContext is used to configure how ActiveMQ is exposed in
            JMX. By default, ActiveMQ uses the MBean server that is started by
            the JVM. For more information, see:

            http://activemq.apache.org/jmx.html
        -->
        <managementContext>
            <managementContext createConnector="false"/>
        </managementContext>

        <persistenceAdapter>
            <!-- defer cleanup/checkpoint -->
            <!-- write in max 62k chunks to max disk io bandwith -->
            <!-- use small number of data files (seldom switch) -->
            <!-- keep index off the disk (in cache) -->

            <kahaDB directory="${activemq.data}/kahadb"
                cleanupInterval="300000" checkpointInterval="50000"
                journalMaxWriteBatchSize="62k"
                journalMaxFileLength="1g"
                indexCacheSize="100000" indexWriteBatchSize="100000"
            />
        </persistenceAdapter>

        <!-- ensure there is loads or memory for destinations -->
        <systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage limit="2 g"/>
                </memoryUsage>
            </systemUsage>
        </systemUsage>


        <!--
            The transport connectors expose ActiveMQ over a given protocol to
            clients and other brokers. For more information, see:

            http://activemq.apache.org/configuring-transports.html
        -->
        <transportConnectors>
            <transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
        </transportConnectors>

    </broker>

</beans>