Tim
Tim

Reputation: 389

Delete ActiveMQ subscribers

I am trying to reset ActiveMQ by deleting all subscribers and topics. I know that I can delete subscribers/topics by clicking delete link in the Web UI. Is there a way to delete them all at once?

Thanks.

Upvotes: 0

Views: 108

Answers (2)

Paul
Paul

Reputation: 1170

I wanted to programmatically delete my (Virtual) topics after running my tests. But you cannot delete topics that still have active (durable) subscribers attached. Working from Justin's answer on another question, I wanted to document a solution using the built-in Jolokia using ActiveMQ v6.1.5, Java21 and SpringBoot3.x.x

For minimalistic POC, comment out the cors-config within the broker itself underneath path /conf/jolokia-access.xml. Please configure proper origins instead!

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setBasicAuth(jolokiaUser, jolokiaPassword);

Object response = restTemplate.postForEntity(
                String.format("http://%s:8161/api/jolokia/", host),
                new HttpEntity<>("""
                        {
                        "type":"exec",
                        "mbean":"org.apache.activemq:brokerName=myBrokerName,clientId=TOPIC.TEST.1-UUID,consumerId=Durable(TOPIC.TEST.1-UUID_TOPIC.TEST.1),destinationName=TOPIC.TEST.1,destinationType=Topic,endpoint=Consumer,type=Broker",
                        "operation":"destroy",
                        }
                        """, headers),
                Object.class
        );

I had trouble finding out the correct path for my mbean, but there's this nifty program called JMXTERM that's downloadable for free from https://docs.cyclopsgroup.org/jmxterm. Simply place the jar on the server that hosts your broker and use the following commands as your broker is running:

java -jar jmxterm-1.0.2-uber.jar    // 1.0.2 -> latest jar version
open host:port                      // your server + jmx-port
beans host                          // your server

Upvotes: 0

Tim
Tim

Reputation: 389

The configuration did what I wanted to do. deleteAllMessagesOnStartup="true"

Upvotes: 0

Related Questions