activemq配置詳解
阿新 • • 發佈:2019-01-30
- <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 -->
- <beanclass="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property
- <value>file:${activemq.base}/conf/credentials.properties</value>
- </property>
- </bean>
- <!-- The <broker> element is used to configure the ActiveMQ broker. -->
- <!-- brokerName:必須定義一個名稱 -->
- <!-- 不使用持久化儲存:persistent="false",注意:記憶體要足夠大 -->
- <brokerxmlns="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 -->
- <policyEntrytopic=">"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多少數量的訊息 -->
- <policyEntryqueue=">"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>
- <managementContextconnectorPort="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% -->
- <kahaDBdirectory="${activemq.base}/data/kahadb"/>
- </persistenceAdapter>
- <!-- System Usage 對整個的broker做全域性設定-->
- <!-- 使用systemUsage,以後,如果引數值設定不當,可能導致整個的q停止相應 -->
- <!-- 好的辦法是:設定systemUsage,同時設定sendFailIfNoSpaceAfterTimeout(多長時間後超時),這個超時資訊會返回給producer。這樣即不會讓amq被撐死,有能夠保證producer不被拖死 -->
- <systemUsage>
- <systemUsagesendFailIfNoSpaceAfterTimeout="1000">
- <memoryUsage>
- <memoryUsagelimit="32 mb"/>
- </memoryUsage>
- <storeUsage>
- <storeUsagelimit="5 gb"/>
- </storeUsage>
- <tempUsage>
- <tempUsagelimit="100 mb"/>
- </tempUsage>
- </systemUsage>
- </systemUsage>
- <!-- 定義連線方式,注意如果只監聽內網ip,需要指定IP地址 -->
- <!-- 可以指定熱備等,使用failover -->
- <transportConnectors>
- <transportConnectorname="manzuoopenwire"uri="tcp://0.0.0.0:63333"/>
- </transportConnectors>
- <!-- 對於broker,可以設定認證 -->
- <!--
- <plugins>
- <simpleAuthenticationPlugin>
- <users>
- <authenticationUserusername="admin"password="password"groups="admins,publishers,consumers"/>
- <authenticationUserusername="publisher"password="password"groups="publishers,consumers"/>
- <authenticationUserusername="consumer"password="password"groups="consumers"/>
- <authenticationUserusername="guest"password="password"groups="guests"/>
- </users>
- </simpleAuthenticationPlugin>
- </plugins>
- -->
- </broker>
- <!-- 可以設定web 管理介面 -->
- <importresource="jetty.xml"/>
- </beans>
- <beans
- xmlns="http://www.springframework.org/schema/beans"
- xmlns:amq="http://activemq.org/config/1.0"
- 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.org/config/1.0 http://activemq.apache.org/schema/activemq-core.xsd
- http://activemq.apache.org/camel/schema/spring>
- <!-- persistent="true"表示要持久化儲存訊息,和子元素persistenceAdapter結合使用 -->
- <!-- dataDirectory預設的儲存持久化資料的目錄 -->
- <!-- brokerName 設定broker的name,在注意在網路上必須是唯一的-->
- <!-- 更多參考http://activemq.apache.org/xbean-xml-reference-50.html#XBeanXMLReference5.0-brokerelement -->
- <broker xmlns="http://activemq.org/config/1.0" brokerName="192.168.1.148" persistent ="true" dataDirectory="${activemq.base}/data" useShutdownHook="false">
- <!-- Destination specific policies using destination names or wildcards -->
- <!-- wildcards意義見http://activemq.apache.org/wildcards.html -->
- <destinationPolicy>
- <policyMap>
- <policyEntries>
- <!-- 這裡使用了wildcards,表示所有以EUCITA開頭的topic -->
- <policyEntry topic="EUCITA.>" producerFlowControl="false" memoryLimit="10mb">
- <!-- 分發策略 -->