準備環(huán)境: jdk 1.8 activemq5.14.3(這里5.8以上版本都可) zookeeper3.3.6 centos7或win10
這里我只做一臺 zookeeper的 如果用zk集群 可以英文逗號隔開
話不多說 直接上配置文件 apache-activemq-5.14.3\conf\activemq.xml
first of all :
配置文件中配置了和zk集群 ,請詳看配置文件
secondly:
配置文件中 配置了queue 30秒沒有處理的消息自動丟棄
topic 過期沒有配置
<beans
xmlns="http://www.springframework.org/schema/beans"
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
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.conf}/credentials.properties</value>
</property>
</bean>
<!-- Allows accessing the server log -->
<bean id="logQuery" class="io.fabric8.insight.log.log4j.Log4jLogQuery"
lazy-init="false" scope="singleton"
init-method="start" destroy-method="stop">
</bean>
<!--
The <broker> element is used to configure the ActiveMQ broker.
-->
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="mybroker" dataDirectory="${activemq.data}">
<destinationPolicy>
<policyMap>
<policyEntries>
<!--步驟一 配置queue消息超時 丟棄到死信隊列 -->
<!-- gcInactiveDestinations="true"啟用清理功能 -->
<!-- inactiveTimoutBeforeGC="30000" Topic或Queue超時時間 單位毫秒-->
<policyEntry queue=">" gcInactiveDestinations="true" inactiveTimoutBeforeGC="30000">
<!--步驟二 設置死信策略-->
<deadLetterStrategy>
<!-- 非持久消息保存到死信隊列 processNonPersistent="true"-->
<!-- 過期消息不保存到死信隊列 processExpired="false" -->
<!-- 過期時間 expiration="30000" 毫秒-->
<sharedDeadLetterStrategy processExpired="false" expiration="30000" />
</deadLetterStrategy>
</policyEntry>
<policyEntry topic=">" >
<pendingMessageLimitStrategy>
<constantPendingMessageLimitStrategy limit="1000"/>
</pendingMessageLimitStrategy>
<!-- 定時丟棄死信隊列 -->
<!-- <deadLetterStrategy>
<sharedDeadLetterStrategy processExpired="true" expiration="30000"/>
</deadLetterStrategy> -->
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
<managementContext>
<managementContext createConnector="false"/>
</managementContext>
<persistenceAdapter>
<!-- kahaDB directory="${activemq.data}/kahadb"/>-->
<!-- LevelDB -->
<!--一旦Broker崩潰住诸,重建索引的速度會非常慢
但是由于其重建索引時間過長耿导,而且索引文件占用磁盤空間過大,所以已經(jīng)不推薦使用逛犹。 -->
<!-- 參數(shù)說明 -->
<!--
replicas:集群activemq 數(shù)量 如果是三臺機器這里寫3 ,當集群中一臺機器掛掉之后 mq會判斷當前有幾臺可用梁剔,并滿足公式 N/2>2 才會正常提供服務
bind:這里是mq提供的地址 端口自定義 三臺機器里面的配置要一致虽画,tips:不一致我還沒有試過
zkAddress:zk服務提供地址 zk集群的話 多臺 用 英文逗號隔開
zkPassword:zk 的acl認證時候的密碼
hostname:可理解為本機機器名稱。 三臺機器都不一致荣病。
zkPath:zk上的存儲節(jié)點位置码撰,自定義 三臺須一致
-->
<replicatedLevelDB
directory="${activemq.data}/leveldb"
replicas="1"
bind="tcp://0.0.0.0:61619"
zkAddress="127.0.0.1:2181"
zkPassword=""
hostname="localhost"
zkPath="/activemq/leveldb-stores"
/>
</persistenceAdapter>
<systemUsage>
<systemUsage>
<memoryUsage>
<memoryUsage percentOfJvmHeap="70" />
</memoryUsage>
<storeUsage>
<storeUsage limit="100 gb"/>
</storeUsage>
<!--
一旦ActiveMQ服務節(jié)點存儲的消息達到了memoryUsage的限制,NON_PERSISTENT Message就會被轉儲到 temp store區(qū)域个盆。雖然我們說過NON_PERSISTENT Message不進行持久化存儲脖岛,但是ActiveMQ為了防止“數(shù)據(jù)洪峰”出現(xiàn)時NON_PERSISTENT Message寫入到磁盤的臨時區(qū)域——tempessage大量堆積致使內存耗盡的情況出現(xiàn),還是會將NON_PERSISTENT Message寫入到磁盤的臨時區(qū)域——temp store颊亮。這個子標記就是為了設置這個temp store區(qū)域的“可用磁盤空間限制”柴梆。
-->
<tempUsage>
<tempUsage limit="50 gb"/>
</tempUsage>
</systemUsage>
</systemUsage>
<!-- 如果有默認的,activemq啟動 這里的端口都需要改動 -->
<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"/>
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ws" uri="ws://0.0.0.0:61614?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>
<!-- 步驟三 配置插件防止消息堆積 配置 插件 -->
<plugins>
<!--timeStampingBrokerPlugin 它使用代理時間戳更新消息上的JMS客戶端時間戳 -->
<!-- 86,400,000ms = 1 day futureOnly=true :實時更新設置的時間 默認false 60秒 -->
<!--ttlCeiling:當不為零時终惑,此值(以毫秒為單位)限制到期時間 -->
<!--zeroExpirationOverride: 當不為零時绍在,此值(以毫秒為單位)將覆蓋尚未設置到期日的消息的到期時間 -->
<timeStampingBrokerPlugin ttlCeiling="30000" zeroExpirationOverride="30000" />
<!-- 丟棄所有死信隊列 插件 <discardingDLQBrokerPlugin dropAll="true" dropTemporaryTopics="true" dropTemporaryQueues="true" /> -->
<!-- 丟死指定死信隊列 <discardingDLQBrokerPlugin dropOnly="MY.ORDER.QUEUE" reportInterval="1000" />-->
<discardingDLQBrokerPlugin dropAll="true" dropTemporaryTopics="true" dropTemporaryQueues="true" />
</plugins>
</broker>
<!--
Enable web consoles, REST and Ajax APIs and demos
The web consoles requires by default login, you can disable this in the jetty.xml file
Take a look at ${ACTIVEMQ_HOME}/conf/jetty.xml for more details
-->
<import resource="jetty.xml"/>
</beans>
tips:levelDB官方已經(jīng)不推薦 O(∩_∩)O