下面是activemq.xml中的配置详解。
- <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-2.0.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">
- <property name="locations">
- <value>file:${activemq.base}/conf/credentials.properties</value>
- </property>
- </bean>
- <!-- The <broker> element is used to configure the ActiveMQ broker. -->
- <!-- brokerName:必须定义一个名称 -->
- <!-- 不使用持久化存储:persistent="false",注意:内存要足够大 -->
- <broker xmlns="http://activemq.apache.org/schema/core" brokerName="testBroker" dataDirectory="${activemq.base}/data" destroyApplicationContextOnStop="true" persistent="true">
- <destinationPolicy>
- <policyMap>
- <policyEntries>
- <!-- 如果设定了<systemUsage>,则全局按照<systemUsage>,这里精细控制每一个q -->
- <!-- 设定了flowcontrol以后,会根据memorylimit的缓冲区设定的大小,决定producer的流速,即:可能拖慢producer -->
- <!-- 设定flowcontrol false后(同时不设定systemUsage),虽然不会拖慢producer,但是可能会占用大量activemq的内存,如果处理仍然不及时,可能最终导致amq outofmemory -->
- <!-- 参考下面<systemUsage>的说明 -->
- <!-- 设定了false以后,表示producer直接都给,直到撑死systemUsage,才报客户端Exception -->
- <policyEntry topic=">" producerFlowControl="false" topicPrefetch="1000" useCache="true">
- <pendingSubscriberPolicy>
- <vmCursor />
- </pendingSubscriberPolicy>
- </policyEntry>
- <!-- 设定true,表示超过memoryLimit以后,就等,等到systemUsage设定的超时时间报Exception -->
- <!-- 尽管可以让systemUsage统一管理全部的,但也就失去了精细管理每一个队列的能力,如果队列有重要和不重要之分,即:有的允许丢数据的,就设定true和memoryLimit;有的不允许的,就单独设定 -->
- <!-- 关于amq的特殊检测参数也在这里设定,参见http://activemq.apache.org/advisory-message.html -->
- <!-- queuePrefetch:一次分配给consumer多少数量的消息 -->
- <policyEntry queue=">" producerFlowControl="true" memoryLimit="4mb" queuePrefetch="1000" useCache="true">
- <!-- Use VM cursor for better latency
- For more information, see:
- http://activemq.apache.org/message-cursors.html
- <pendingQueuePolicy>
- <vmQueueCursor/>
- </pendingQueuePolicy>
- -->
- </policyEntry>
- </policyEntries>
- </policyMap>
- </destinationPolicy>
- <!-- 设定jmx管理端口 -->
- <managementContext>
- <managementContext connectorPort="62222" jmxDomainName="testDomain" createConnector="true"/>
- </managementContext>
- <!-- 设定持久化方案 -->
- <persistenceAdapter>
- <!-- 稳定性最强的一个 -->
- <!-- <amqPersistenceAdapter useNIO="true" directory="target/Broker2-data/activemq-data" syncOnWrite="true" indexPageSize="16kb" persistentIndex="true" indexMaxBinSize="100" maxFileLength="10mb" maxCheckpointMessageAddSize="32kb" cleanupInterval="3000" checkpointInterval="20000" /> -->
- <!-- 对于恢复来说,这个存储不能保证完全不丢数据。它比一般存储的快50% -->
- <kahaDB directory="${activemq.base}/data/kahadb" />
- </persistenceAdapter>
- <!-- System Usage 对整个的broker做全局设定-->
- <!-- 使用systemUsage,以后,如果参数值设定不当,可能导致整个的q停止相应 -->
- <!-- 好的办法是:设定systemUsage,同时设定sendFailIfNoSpaceAfterTimeout(多长时间后超时),这个超时信息会返回给producer。这样即不会让amq被撑死,有能够保证producer不被拖死 -->
- <systemUsage>
- <systemUsage sendFailIfNoSpaceAfterTimeout="1000">
- <memoryUsage>
- <memoryUsage limit="32 mb"/>
- </memoryUsage>
- <storeUsage>
- <storeUsage limit="5 gb"/>
- </storeUsage>
- <tempUsage>
- <tempUsage limit="100 mb"/>
- </tempUsage>
- </systemUsage>
- </systemUsage>
- <!-- 定义连接方式,注意如果只监听内网ip,需要指定IP地址 -->
- <!-- 可以指定热备等,使用failover -->
- <transportConnectors>
- <transportConnector name="manzuoopenwire" uri="tcp://0.0.0.0:63333"/>
- </transportConnectors>
- <!-- 对于broker,可以设定认证 -->
- <!--
- <plugins>
- <simpleAuthenticationPlugin>
- <users>
- <authenticationUser username="admin" password="password" groups="admins,publishers,consumers"/>
- <authenticationUser username="publisher" password="password" groups="publishers,consumers"/>
- <authenticationUser username="consumer" password="password" groups="consumers"/>
- <authenticationUser username="guest" password="password" groups="guests"/>
- </users>
- </simpleAuthenticationPlugin>
- </plugins>
- -->
- </broker>
- <!-- 可以设定web 管理界面 -->
- <import resource="jetty.xml"/>
- </beans>
另外,有一个满座网关于amq的培训ppt,有需要的可以拿去~~