版本 5 XML 設定
使用 ActiveMQ Classic 5 > 版本 5 XML 設定
- 傳輸連接器,由傳輸通道和線路格式組成。TODO:新增一個連結到頁面,說明什麼是傳輸連接器,以及如何設定和使用它們。
- 使用網路通道或探索的網路連接器。TODO:新增一個連結到頁面,說明什麼是網路連接器,以及如何設定和使用它們。
- 探索代理程式。TODO:新增一個連結到頁面,說明什麼是探索代理程式,以及如何設定和使用它們。
- 持久性提供者和位置。TODO:新增一個連結到頁面,說明什麼是持久性提供者,以及如何設定和使用它們。
- 自訂訊息容器(例如最後影像快取等)。
我們使用 XBean 來執行 XML 設定。
有關 XML 的詳細資訊,請參閱 Xml 參考。
請小心 Broker 名稱和 URI
請確保您在 Broker 的名稱中不要使用任何奇怪的字元,因為它們會被轉換為 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&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&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>
在二進位發行版本中,有一個 activemq 指令碼,可讓您從命令列輕鬆地將訊息 Broker 作為獨立程序執行,前提是您的 PATH 中有 $ACTIVEMQ_HOME/bin 目錄。
設定嵌入式 Broker
您也可以使用 XML 設定來設定嵌入式 Broker。例如,使用 JNDI 設定機制,您可以執行以下操作 BrokerXmlConfigFromJNDITest。
或者,如果您想透過 Java 程式碼明確設定嵌入式 Broker,您可以執行以下操作 BrokerXmlConfigTest。
使用者提交的設定
我們有一個頁面,允許使用者提交其設定的詳細資訊。
背景
由於 ActiveMQ Classic 對於傳輸、線路格式、持久性以及許多其他事項有許多策略模式外掛程式,我們希望保持設定格式的開放性,以便開發人員可以按照您希望的任何方向設定和擴充 ActiveMQ Classic。
因此,我們使用 Spring XML 設定檔格式,該格式允許將任何 Bean / POJO 連接在一起並進行設定。然而,有時 Spring 的 XML 可能有點冗長,因此我們實作了一個 ActiveMQ Classic 對 Spring XML 的擴充,它了解您可能會執行的常見標準 ActiveMQ Classic 操作(例如,連接器、wireFormat、serverTransport、持久性等標籤)- 但在任何時候,您都可以退回到正常的 Spring 操作方式(使用 bean、property 等標籤)。
若要查看我們使用的 XML 檔案的說明文件或取得 XSD/DTD 的存取權,請參閱 Xml 參考。