ActiveMQ - delete/purge all queue via command line

落花浮王杯 提交于 2019-12-05 16:42:56

问题


Is there a way to delete / purge all queues in ActiveMQ via the command line (win/linux)? I could only find the commands for a specific queue. Or maybe there's a way to do this via the activeMQ admin? Again, I only found how to delete/purge the queues one by one, which can be very tedious.

Thanks!


回答1:


You can do tweak your activemq.xml a bit:

<broker deleteAllMessagesOnStartup="true"  ...>

This works with KahaDB message stores (it has problems with JDBC message stores), all your messages get deleted and subsequently queues are cleared.

As you want all queues to be deleted, restarting the broker won't be a costly option to clean everything up.

The purge will happen on 'every' restart




回答2:


I developed my own ActiveMQ command line utility (activemq-cli) to do this. You can find it here: https://github.com/antonwierenga/activemq-cli (command 'purge-all-queues' or 'remove-all-queues').




回答3:


As of version 5.0 it looks like this can be done using the CLI provided with ActiveMQ itself:

$ ActiveMQ/bin/activemq purge



回答4:


Another possibility is to deploy a small Camel route in a container (e.g. Apache ServiceMix) or simply by executing a java program which contain the route.

For example here is the route I currently use on my development computer where I also have the ServiceMix installed:

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



回答5:


1- go to amq bin folder, in my case:

cd /opt/amq/bin

2- run amq client:

./client

3- run purge on desired queue

activemq:purge <QUEUE NAME HERE>


来源:https://stackoverflow.com/questions/27271276/activemq-delete-purge-all-queue-via-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!