Xml 配置
我们支持用于配置 ActiveMQ Classic 消息代理的 XML 部署描述符。可以配置许多内容,例如
因此我们决定使用 XML 将使此配置更容易。从 4.0 版本开始,我们使用 XBean 来执行 XML 配置。
有关 XML 的详细信息,请参见 Xml 参考
小心代理名称和 URI
确保您不要在代理名称中使用任何奇怪的字符,因为它们将被转换为 URI,而 URI 不允许像下划线这样的内容 等等。
示例
默认 ActiveMQ Classic 配置:当前默认配置。
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="https://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
https://activemq.apache.org/schema/core https://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">
<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.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}">
<!--
For better performances use VM cursor and small memory limit.
For more information, see:
https://activemq.apache.org/message-cursors.html
Also, if your producer is "hanging", it's probably due to producer flow control.
For more information, see:
https://activemq.apache.org/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.apache.org/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.apache.org/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.apache.org/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.apache.org/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.apache.org/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.apache.org/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>
从二进制发行版开始,从 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 参考