下面是activemq.xml中的配置详解。

  1. <beans 
  2.   xmlns="http://www.springframework.org/schema/beans" 
  3.   xmlns:amq="http://activemq.apache.org/schema/core" 
  4.   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  5.   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
  6.   http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"> 
  7.  
  8.     <!-- Allows us to use system properties as variables in this configuration file --> 
  9.     <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
  10.         <property name="locations"> 
  11.             <value>file:${activemq.base}/conf/credentials.properties</value> 
  12.         </property>       
  13.     </bean> 
  14.  
  15.     <!-- The <broker> element is used to configure the ActiveMQ broker. --> 
  16.      
  17.     <!-- brokerName:必须定义一个名称 --> 
  18.     <!-- 不使用持久化存储:persistent="false",注意:内存要足够大 --> 
  19.     <broker xmlns="http://activemq.apache.org/schema/core" brokerName="testBroker" dataDirectory="${activemq.base}/data" destroyApplicationContextOnStop="true" persistent="true"> 
  20.   
  21.                
  22.         <destinationPolicy> 
  23.             <policyMap> 
  24.               <policyEntries> 
  25.               <!-- 如果设定了<systemUsage>,则全局按照<systemUsage>,这里精细控制每一个q --> 
  26.               <!-- 设定了flowcontrol以后,会根据memorylimit的缓冲区设定的大小,决定producer的流速,即:可能拖慢producer --> 
  27.               <!-- 设定flowcontrol false后(同时不设定systemUsage),虽然不会拖慢producer,但是可能会占用大量activemq的内存,如果处理仍然不及时,可能最终导致amq outofmemory --> 
  28.               <!-- 参考下面<systemUsage>的说明 --> 
  29.               <!-- 设定了false以后,表示producer直接都给,直到撑死systemUsage,才报客户端Exception --> 
  30.                 <policyEntry topic=">" producerFlowControl="false" topicPrefetch="1000" useCache="true"> 
  31.                   <pendingSubscriberPolicy> 
  32.                     <vmCursor /> 
  33.                   </pendingSubscriberPolicy> 
  34.                 </policyEntry> 
  35.                  
  36.                 <!-- 设定true,表示超过memoryLimit以后,就等,等到systemUsage设定的超时时间报Exception --> 
  37.                 <!-- 尽管可以让systemUsage统一管理全部的,但也就失去了精细管理每一个队列的能力,如果队列有重要和不重要之分,即:有的允许丢数据的,就设定true和memoryLimit;有的不允许的,就单独设定 --> 
  38.                 <!-- 关于amq的特殊检测参数也在这里设定,参见http://activemq.apache.org/advisory-message.html --> 
  39.                 <!-- queuePrefetch:一次分配给consumer多少数量的消息 --> 
  40.                 <policyEntry queue=">" producerFlowControl="true" memoryLimit="4mb" queuePrefetch="1000" useCache="true"> 
  41.                   <!-- Use VM cursor for better latency 
  42.                        For more information, see: 
  43.                         
  44.                        http://activemq.apache.org/message-cursors.html 
  45.                         
  46.                   <pendingQueuePolicy> 
  47.                     <vmQueueCursor/> 
  48.                   </pendingQueuePolicy> 
  49.                   --> 
  50.                 </policyEntry> 
  51.               </policyEntries> 
  52.             </policyMap> 
  53.         </destinationPolicy>  
  54.   
  55.          
  56.         <!-- 设定jmx管理端口 --> 
  57.         <managementContext> 
  58.             <managementContext connectorPort="62222" jmxDomainName="testDomain" createConnector="true"/> 
  59.         </managementContext> 
  60.  
  61.         <!-- 设定持久化方案 --> 
  62.         <persistenceAdapter> 
  63.             <!-- 稳定性最强的一个 --> 
  64.             <!-- <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" /> --> 
  65.             <!-- 对于恢复来说,这个存储不能保证完全不丢数据。它比一般存储的快50% --> 
  66.             <kahaDB directory="${activemq.base}/data/kahadb" /> 
  67.         </persistenceAdapter> 
  68.          
  69.          
  70.           <!-- System Usage 对整个的broker做全局设定--> 
  71.           <!-- 使用systemUsage,以后,如果参数值设定不当,可能导致整个的q停止相应 --> 
  72.           <!-- 好的办法是:设定systemUsage,同时设定sendFailIfNoSpaceAfterTimeout(多长时间后超时),这个超时信息会返回给producer。这样即不会让amq被撑死,有能够保证producer不被拖死 --> 
  73.           <systemUsage> 
  74.             <systemUsage sendFailIfNoSpaceAfterTimeout="1000"> 
  75.                 <memoryUsage> 
  76.                     <memoryUsage limit="32 mb"/> 
  77.                 </memoryUsage> 
  78.                 <storeUsage> 
  79.                     <storeUsage limit="5 gb"/> 
  80.                 </storeUsage> 
  81.                 <tempUsage> 
  82.                     <tempUsage limit="100 mb"/> 
  83.                 </tempUsage> 
  84.             </systemUsage> 
  85.         </systemUsage> 
  86.          
  87.         <!-- 定义连接方式,注意如果只监听内网ip,需要指定IP地址 --> 
  88.         <!-- 可以指定热备等,使用failover --> 
  89.         <transportConnectors> 
  90.             <transportConnector name="manzuoopenwire" uri="tcp://0.0.0.0:63333"/> 
  91.         </transportConnectors> 
  92.  
  93.         <!-- 对于broker,可以设定认证 --> 
  94.         <!-- 
  95.         <plugins> 
  96.             <simpleAuthenticationPlugin> 
  97.                 <users> 
  98.                     <authenticationUser username="admin" password="password" groups="admins,publishers,consumers"/> 
  99.                     <authenticationUser username="publisher" password="password" groups="publishers,consumers"/> 
  100.                     <authenticationUser username="consumer" password="password" groups="consumers"/> 
  101.                     <authenticationUser username="guest" password="password" groups="guests"/> 
  102.                 </users> 
  103.             </simpleAuthenticationPlugin> 
  104.         </plugins> 
  105.         --> 
  106.     </broker> 
  107.      
  108.      
  109.     <!-- 可以设定web 管理界面 --> 
  110.     <import resource="jetty.xml"/> 
  111. </beans> 

另外,有一个满座网关于amq的培训ppt,有需要的可以拿去~~

posted on 2013-05-06 19:17  yunfuby  阅读(1191)  评论(2编辑  收藏  举报