Xml 配置

使用 ActiveMQ Classic > Xml 配置

我們支援 XML 部署描述符,用於配置 ActiveMQ Classic 訊息代理程式。 有許多可以配置的項目,例如:

因此,我們決定使用 XML 會讓這種配置變得更加容易。從 4.0 版開始,我們使用 XBean 來執行 XML 配置。

有關 XML 的詳細資訊,請參閱 Xml 參考

請小心代理程式名稱和 URI

請確保不要在代理程式的名稱中使用任何奇怪的字元,因為它們會轉換為 URI,而 URI 不允許在其中使用底線之類的東西

範例

預設的 ActiveMQ Classic 配置:目前的預設配置

<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:amq="https://activemq.dev.org.tw/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
  https://activemq.dev.org.tw/schema/core https://activemq.dev.org.tw/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">
        <property name="locations">
            <value>file:${activemq.conf}/credentials.properties</value>
        </property>
    </bean>

    <!--
        The <broker> element is used to configure the ActiveMQ Classic broker.
    -->
    <broker xmlns="https://activemq.dev.org.tw/schema/core" brokerName="localhost" dataDirectory="${activemq.data}">

        <!--
            For better performances use VM cursor and small memory limit.
            For more information, see:

            https://activemq.dev.org.tw/message-cursors.html

            Also, if your producer is "hanging", it's probably due to producer flow control.
            For more information, see:
            https://activemq.dev.org.tw/producer-flow-control.html
        -->

        <destinationPolicy>
            <policyMap>
              <policyEntries>
                <policyEntry topic=">" producerFlowControl="true">
                    <!-- The constantPendingMessageLimitStrategy is used to prevent
                         slow topic consumers to block producers and affect other consumers
                         by limiting the number of messages that are retained
                         For more information, see:

                         https://activemq.dev.org.tw/slow-consumer-handling.html

                    -->
                  <pendingMessageLimitStrategy>
                    <constantPendingMessageLimitStrategy limit="1000"/>
                  </pendingMessageLimitStrategy>
                </policyEntry>
                <policyEntry queue=">" producerFlowControl="true" memoryLimit="1mb">
                  <!-- Use VM cursor for better latency
                       For more information, see:

                       https://activemq.dev.org.tw/message-cursors.html

                  <pendingQueuePolicy>
                    <vmQueueCursor/>
                  </pendingQueuePolicy>
                  -->
                </policyEntry>
              </policyEntries>
            </policyMap>
        </destinationPolicy>


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

            https://activemq.dev.org.tw/jmx.html
        -->
        <managementContext>
            <managementContext createConnector="false"/>
        </managementContext>

        <!--
            Configure message persistence for the broker. The default persistence
            mechanism is the KahaDB store (identified by the kahaDB tag).
            For more information, see:

            https://activemq.dev.org.tw/persistence.html
        -->
        <persistenceAdapter>
            <kahaDB directory="${activemq.data}/kahadb"/>
        </persistenceAdapter>


          <!--
            The systemUsage controls the maximum amount of space the broker will
            use before slowing down producers. For more information, see:
            https://activemq.dev.org.tw/producer-flow-control.html
            If using ActiveMQ Classic embedded - the following limits could safely be used:

        <systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage limit="20 mb"/>
                </memoryUsage>
                <storeUsage>
                    <storeUsage limit="1 gb"/>
                </storeUsage>
                <tempUsage>
                    <tempUsage limit="100 mb"/>
                </tempUsage>
            </systemUsage>
        </systemUsage>
        -->
          <systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage limit="64 mb"/>
                </memoryUsage>
                <storeUsage>
                    <storeUsage limit="100 gb"/>
                </storeUsage>
                <tempUsage>
                    <tempUsage limit="50 gb"/>
                </tempUsage>
            </systemUsage>
        </systemUsage>

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

            https://activemq.dev.org.tw/configuring-transports.html
        -->
        <transportConnectors>
            <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
            <transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
        </transportConnectors>

        <!-- destroy the spring context on shutdown to stop jetty -->
        <shutdownHooks>
            <bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook" />
        </shutdownHooks>

    </broker>

    <!--
        Enable web consoles, REST and Ajax APIs and demos

        Take a look at ${ACTIVEMQ_HOME}/conf/jetty.xml for more details
    -->
    <import resource="jetty.xml"/>

</beans>

從二進位發行版本開始,從 1.1 版開始,有一個 *activemq* 腳本,允許您從命令列輕鬆地將訊息代理程式作為獨立程序執行,前提是 $ACTIVEMQ_HOME/bin 目錄在您的 PATH 中。

AMQ 4.x 如果 myConfig.xml 在類別路徑中

activemq xbean:myConfig.xml

或者使用檔案路徑系統

activemq xbean:file:../conf/myConfig.xml

AMQ 3.x

activemq myConfig.xml

或者使用預設的設定檔,它只是

activemq

如果您有原始碼發行版本,您可以使用 Maven 執行代理程式,並指定其中一個設定檔,如下所示
在 assembly 模組下執行

maven server -Dconfig=xbean:file:src/release/conf/activemq.xml

如果您的 類別路徑設定正確,您可以從命令列達成相同的效果

java org.apache.activemq.broker.Main xbean:file:src/release/conf/activemq.xml

配置嵌入式代理程式

您也可以使用 XML 配置來配置嵌入式代理程式。 例如,使用 JNDI 配置機制,您可以執行以下操作
BrokerXmlConfigFromJNDITest
或者,如果您想透過 Java 程式碼明確配置嵌入式代理程式,您可以執行以下操作
BrokerXmlConfigStartTest

使用者提交的配置

我們有一個頁面,允許使用者提交他們的配置詳細資訊。

背景

由於 ActiveMQ Classic 針對傳輸、線路格式、持久性以及許多其他東西有這麼多策略模式外掛程式,我們希望保持配置格式開放,以便您開發人員可以朝任何您希望的方向配置和擴展 ActiveMQ Classic。

因此,我們使用 Spring XML 設定檔格式,它允許將任何 bean / POJO 連接在一起並進行配置。然而,Spring 的 XML 有時可能會有點冗長,因此我們實現了 Spring XML 的 ActiveMQ Classic 擴充功能,它了解您可能執行的常見標準 ActiveMQ Classic 操作(例如 connector、wireFormat、serverTransport、persistence 之類的標籤) – 但在任何時候您都可以回歸到使用普通 Spring 的方式做事(使用 bean、property 等標籤)。

若要查看我們使用的 XML 檔案的文件,或取得 XSD/DTD 的存取權,請參閱Xml 參考

Apache、ActiveMQ、Apache ActiveMQ、Apache 羽毛標誌和 Apache ActiveMQ 專案標誌是 Apache 軟體基金會的商標。 版權所有 © 2024,Apache 軟體基金會。 依Apache 授權條款 2.0 授權。