ActiveMQ - 通过命令行删除/清除所有队列

时间:2014-12-03 12:01:03

标签: jms activemq message-queue

有没有办法通过命令行(win / linux)删除/清除ActiveMQ中的所有队列? 我只能找到特定队列的命令。 或者也许有办法通过activeMQ管理员这样做?我再次找到了如何逐个删除/清除队列,这可能非常繁琐。

谢谢!

5 个答案:

答案 0 :(得分:15)

您可以稍微调整activemq.xml

<broker deleteAllMessagesOnStartup="true"  ...>

这适用于KahaDB消息存储(它有JDBC消息存储存在问题),所有消息都被删除,随后队列被清除。

如果您希望删除所有队列,重新启动代理将不是一个昂贵的选项来清理所有内容。

答案 1 :(得分:4)

我开发了自己的ActiveMQ命令行实用程序(activemq-cli)来执行此操作。您可以在此处找到它:https://github.com/antonwierenga/activemq-cli(命令&#39;清除所有队列&#39;或&#39;删除所有队列&#39;)。

答案 2 :(得分:3)

从5.0版开始,它看起来可能是done using the CLI provided with ActiveMQ本身:

$ ActiveMQ/bin/activemq purge

答案 3 :(得分:0)

另一种可能性是在容器(例如Apache ServiceMix)中部署一个小的Camel路由,或者只是通过执行包含该路由的java程序。

例如,这里是我目前在我的开发计算机上使用的路径,我也安装了ServiceMix:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0" 
  xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" 
  xsi:schemaLocation="
       http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
       http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
       http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd">

    <cm:property-placeholder persistent-id="amq.cleanup" update-strategy="reload">
        <cm:default-properties>
            <cm:property name="amq.local.url" value="tcp://localhost:61616" />
        </cm:default-properties>
    </cm:property-placeholder>

    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
        <onException useOriginalMessage="true">
            <exception>java.lang.Exception</exception>
            <handled>
                <constant>true</constant>
            </handled>
            <to uri="activemq:queue:CLEANUP_DLQ" />
        </onException>

        <route id="drop-all-queues" autoStartup="true">
            <from uri="activemq:queue:*.>" />
            <stop/>
        </route>
    </camelContext>

    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="brokerURL" value="${amq.local.url}" />
    </bean>
</blueprint>

答案 4 :(得分:0)

1-以我为例,转到amq bin文件夹:

cd /opt/amq/bin

2-运行amq客户端:

./client

3-在所需队列上运行清除

activemq:purge <QUEUE NAME HERE>