内存配置、流量控制配置 (ActiveMQ内存溢出解决思路--主题与订阅模式)
消息流量控制配置:该配置是默认打开的,即内存将耗尽时会发生流量控制,这样MQ会减少生产者的消息,导致某些数据丢失;所以在默认配置下,MQ在原理上不会出现内存溢出的问题;
内存配置:如果不想数据丢失,就需要关闭流量控制,但是如果MQ处理消息量过大,容易导致AMQ的内存溢出,解决办法增大内存;
配置conf\acitvemq.xml文件
<!-- Destination specific policies using destination names or wildcards -->
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic=">" memoryLimit="32mb" producerFlowControl="false">
<!-- you can add other policies too such as these
<dispatchPolicy>
<strictOrderDispatchPolicy/>
</dispatchPolicy>
<subscriptionRecoveryPolicy>
<lastImageSubscriptionRecoveryPolicy/>
</subscriptionRecoveryPolicy>
-->
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
<!-- The maximum about of space the broker will use before slowing down producers -->
<systemUsage>
<systemUsage>
<memoryUsage>
<memoryUsage limit="20 mb"/>
</memoryUsage>
<storeUsage>
<storeUsage limit="1 gb" name="foo"/>
</storeUsage>
<tempUsage>
<tempUsage limit="100 mb"/>
</tempUsage>
</systemUsage>
</systemUsage>
这里需要继续深入:MQ的消费者存在,但是该消费者属于挂起状态,那么消息会堆积,很快发生内存溢出,单纯增加内存不能从根本上解决问题。