ActiveMQ消息隊列過多導致客戶端連接失敗

一、異常描述

jvm 1    | Exception in thread "ActiveMQ BrokerService[localhost] Task-997" java.lang.OutOfMemoryError: unable to create new native thread
jvm 1    |      at java.lang.Thread.start0(Native Method)
jvm 1    |      at java.lang.Thread.start(Unknown Source)
jvm 1    |      at org.apache.activemq.thread.DedicatedTaskRunner.<init>(DedicatedTaskRunner.java:51)
jvm 1    |      at org.apache.activemq.thread.TaskRunnerFactory.createTaskRunner(TaskRunnerFactory.java:140)
jvm 1    |      at org.apache.activemq.broker.TransportConnection.start(TransportConnection.java:1067)
jvm 1    |      at org.apache.activemq.broker.TransportConnector$1$1.run(TransportConnector.java:218)
jvm 1    |      at java.lang.Thread.run(Unknown Source)

jvm 1    | ERROR | Could not accept connection  : org.apache.activemq.transport.tcp.ExceededMaximumConnectionsException: Exceeded the maximum number of allowed
client connections. See the 'maximumConnections' property on the TCP transport configuration URI in the ActiveMQ configuration file (e.g., activemq.xml)

二、問題排查

消息隊列堆積太多,導致jvm內存不足,瀏覽器訪問mq後臺管理頁面發現有很多無用的消息隊列

三、解決方式

配置自動清除無用的消息隊列,打開activemq.xml文件(\apache-activemq-5.14.3\conf\activemq.xml),broker節點添加schedulePeriodForDestinationPurge="10000"
broker節點下的destinationPolicy添加以下紅色參數:

<destinationPolicy>
            <policyMap>
              <policyEntries>
                <policyEntry topic=">" gcInactiveDestinations="true" inactiveTimoutBeforeGC="30000">
                  <pendingMessageLimitStrategy>
                    <constantPendingMessageLimitStrategy limit="1000"/>
                  </pendingMessageLimitStrategy>
                </policyEntry>
              </policyEntries>
            </policyMap>
</destinationPolicy>

參數含義:
schedulePeriodForDestinationPurge:10000 每十秒檢查一次,默認爲0,此功能關閉
gcInactiveDestinations: true 刪除掉不活動隊列,默認爲false
inactiveTimoutBeforeGC:30000 不活動30秒後刪除,默認爲60秒

配置後,重啓mq服務器即可

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章