ActiveMQ-删除不活动的队列(Delete Inactive Destinations)

一般情况下,ActiveMQ的queue在不使用之后,可以通过web控制台或是JMX方式来删除掉。

当然,也可以通过配置,使得broker可以自动探测到无用的队列(一定时间内为空的队列)并删除掉,回收响应资源。

修改conf文件下activemq.xml文件

<broker xmlns="http://activemq.apache.org/schema/core" schedulePeriodForDestinationPurge="10000">

    <destinationPolicy>
       <policyMap>
          <policyEntries>
             <policyEntry queue=">" gcInactiveDestinations="true" inactiveTimoutBeforeGC="30000"/>
          </policyEntries>
       </policyMap>
    </destinationPolicy>
        
  </broker>

schedulePeriodForDestinationPurge:10000  每十秒检查一次,默认为0,此功能关闭

 

gcInactiveDestinations: true  删除掉不活动队列,默认为false

inactiveTimoutBeforeGC:30000 不活动30秒后删除,默认为60秒

 

修改后的完整xml如下:

<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">

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <value>file:${activemq.conf}/credentials.properties</value>
        </property>
    </bean>

    <broker xmlns="http://activemq.apache.org/schema/core" schedulePeriodForDestinationPurge="10000" brokerName="localhost" dataDirectory="${activemq.data}">

        <destinationPolicy>
            <policyMap>
              <policyEntries>
                <policyEntry topic=">" producerFlowControl="true" memoryLimit="1mb">
                  <pendingSubscriberPolicy>
                    <vmCursor />
                  </pendingSubscriberPolicy>
                </policyEntry>
                <policyEntry queue=">" producerFlowControl="true" memoryLimit="1mb">
                </policyEntry>
				<policyEntry queue=">" gcInactiveDestinations="true" inactiveTimoutBeforeGC="30000"/>
              </policyEntries>
            </policyMap>
        </destinationPolicy>

        <managementContext>
            <managementContext createConnector="false"/>
        </managementContext>

        <persistenceAdapter>
            <kahaDB directory="${activemq.data}/kahadb"/>
        </persistenceAdapter>

          <systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage limit="64 mb"/>
                </memoryUsage>
                <storeUsage>
                    <storeUsage limit="100 gb"/>
                </storeUsage>
                <tempUsage>
                    <tempUsage limit="50 gb"/>
                </tempUsage>
            </systemUsage>
        </systemUsage>

        <transportConnectors>
            <transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
        </transportConnectors>

    </broker>

  
    <import resource="jetty.xml"/>

</beans>

 

由于ActiveMQ使用时自动创建Destination,并且默认情况下不会删除掉,这种只增加不减少,导致在queue创建频繁的情况下,本功能非常有用。

 

你可能感兴趣的:(activemq)