1. 程式人生 > >activemq配置詳解

activemq配置詳解

下面是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.     <!-- Allows us to use system properties as variables in this configuration file -->
  8.     <beanclass="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  9.         <property
    name="locations">
  10.             <value>file:${activemq.base}/conf/credentials.properties</value>
  11.         </property>
  12.     </bean>
  13.     <!-- The <broker> element is used to configure the ActiveMQ broker. -->
  14.     <!-- brokerName:必須定義一個名稱 -->
  15.     <!-- 不使用持久化儲存:persistent="false",注意:記憶體要足夠大 -->
  16.     <brokerxmlns="http://activemq.apache.org/schema/core"brokerName="testBroker"dataDirectory="${activemq.base}/data"destroyApplicationContextOnStop="true"persistent="true">
  17.         <destinationPolicy>
  18.             <policyMap>
  19.               <policyEntries>
  20.               <!-- 如果設定了<systemUsage>,則全域性按照<systemUsage>,這裡精細控制每一個q -->
  21.               <!-- 設定了flowcontrol以後,會根據memorylimit的緩衝區設定的大小,決定producer的流速,即:可能拖慢producer -->
  22.               <!-- 設定flowcontrol false後(同時不設定systemUsage),雖然不會拖慢producer,但是可能會佔用大量activemq的記憶體,如果處理仍然不及時,可能最終導致amq outofmemory -->
  23.               <!-- 參考下面<systemUsage>的說明 -->
  24.               <!-- 設定了false以後,表示producer直接都給,直到撐死systemUsage,才報客戶端Exception -->
  25.                 <policyEntrytopic=">"producerFlowControl="false"topicPrefetch="1000"useCache="true">
  26.                   <pendingSubscriberPolicy>
  27.                     <vmCursor/>
  28.                   </pendingSubscriberPolicy>
  29.                 </policyEntry>
  30.                 <!-- 設定true,表示超過memoryLimit以後,就等,等到systemUsage設定的超時時間報Exception -->
  31.                 <!-- 儘管可以讓systemUsage統一管理全部的,但也就失去了精細管理每一個佇列的能力,如果佇列有重要和不重要之分,即:有的允許丟資料的,就設定true和memoryLimit;有的不允許的,就單獨設定 -->
  32.                 <!-- 關於amq的特殊檢測引數也在這裡設定,參見http://activemq.apache.org/advisory-message.html -->
  33.                 <!-- queuePrefetch:一次分配給consumer多少數量的訊息 -->
  34.                 <policyEntryqueue=">"producerFlowControl="true"memoryLimit="4mb"queuePrefetch="1000"useCache="true">
  35.                   <!-- Use VM cursor for better latency 
  36.                        For more information, see: 
  37.                        http://activemq.apache.org/message-cursors.html 
  38.                   <pendingQueuePolicy>
  39.                     <vmQueueCursor/>
  40.                   </pendingQueuePolicy>
  41.                   -->
  42.                 </policyEntry>
  43.               </policyEntries>
  44.             </policyMap>
  45.         </destinationPolicy>
  46.         <!-- 設定jmx管理埠 -->
  47.         <managementContext>
  48.             <managementContextconnectorPort="62222"jmxDomainName="testDomain"createConnector="true"/>
  49.         </managementContext>
  50.         <!-- 設定持久化方案 -->
  51.         <persistenceAdapter>
  52.             <!-- 穩定性最強的一個 -->
  53.             <!-- <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" /> -->
  54.             <!-- 對於恢復來說,這個儲存不能保證完全不丟資料。它比一般儲存的快50% -->
  55.             <kahaDBdirectory="${activemq.base}/data/kahadb"/>
  56.         </persistenceAdapter>
  57.           <!-- System Usage 對整個的broker做全域性設定-->
  58.           <!-- 使用systemUsage,以後,如果引數值設定不當,可能導致整個的q停止相應 -->
  59.           <!-- 好的辦法是:設定systemUsage,同時設定sendFailIfNoSpaceAfterTimeout(多長時間後超時),這個超時資訊會返回給producer。這樣即不會讓amq被撐死,有能夠保證producer不被拖死 -->
  60.           <systemUsage>
  61.             <systemUsagesendFailIfNoSpaceAfterTimeout="1000">
  62.                 <memoryUsage>
  63.                     <memoryUsagelimit="32 mb"/>
  64.                 </memoryUsage>
  65.                 <storeUsage>
  66.                     <storeUsagelimit="5 gb"/>
  67.                 </storeUsage>
  68.                 <tempUsage>
  69.                     <tempUsagelimit="100 mb"/>
  70.                 </tempUsage>
  71.             </systemUsage>
  72.         </systemUsage>
  73.         <!-- 定義連線方式,注意如果只監聽內網ip,需要指定IP地址 -->
  74.         <!-- 可以指定熱備等,使用failover -->
  75.         <transportConnectors>
  76.             <transportConnectorname="manzuoopenwire"uri="tcp://0.0.0.0:63333"/>
  77.         </transportConnectors>
  78.         <!-- 對於broker,可以設定認證 -->
  79.         <!-- 
  80.         <plugins>
  81.             <simpleAuthenticationPlugin>
  82.                 <users>
  83.                     <authenticationUserusername="admin"password="password"groups="admins,publishers,consumers"/>
  84.                     <authenticationUserusername="publisher"password="password"groups="publishers,consumers"/>
  85.                     <authenticationUserusername="consumer"password="password"groups="consumers"/>
  86.                     <authenticationUserusername="guest"password="password"groups="guests"/>
  87.                 </users>
  88.             </simpleAuthenticationPlugin>
  89.         </plugins>
  90.         -->
  91.     </broker>
  92.     <!-- 可以設定web 管理介面 -->
  93.     <importresource="jetty.xml"/>
  94. </beans>
  1. <beans  
  2. xmlns="http://www.springframework.org/schema/beans"  
  3. xmlns:amq="http://activemq.org/config/1.0"  
  4. 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  
  5. http://activemq.org/config/1.0 http://activemq.apache.org/schema/activemq-core.xsd  
  6. http://activemq.apache.org/camel/schema/spring>  
  7. <!-- persistent="true"表示要持久化儲存訊息,和子元素persistenceAdapter結合使用 -->  
  8. <!-- dataDirectory預設的儲存持久化資料的目錄 -->  
  9. <!-- brokerName 設定broker的name,在注意在網路上必須是唯一的-->  
  10. <!-- 更多參考http://activemq.apache.org/xbean-xml-reference-50.html#XBeanXMLReference5.0-brokerelement -->  
  11. <broker xmlns="http://activemq.org/config/1.0" brokerName="192.168.1.148" persistent ="true" dataDirectory="${activemq.base}/data" useShutdownHook="false">  
  12. <!-- Destination specific policies using destination names or wildcards -->  
  13. <!-- wildcards意義見http://activemq.apache.org/wildcards.html -->  
  14. <destinationPolicy>  
  15. <policyMap>  
  16. <policyEntries>  
  17. <!-- 這裡使用了wildcards,表示所有以EUCITA開頭的topic -->  
  18. <policyEntry topic="EUCITA.>" producerFlowControl="false" memoryLimit="10mb">  
  19. <!-- 分發策略 -->