Once a new Queue or Topic is created on the broker, the destination is permanently persisted. How do I cleanup old destinations?

Solution Unverified - Updated -

Environment

  • Fuse Message Broker 5.x

Issue

  • How do I remove a Queue or Topic from the broker?

  • Once a new Queue or Topic is created on the broker, the destination is permanently persisted. How do I cleanup old destinations?

  • How do I programatically remove a Queue or Topic from the Fuse Message Broker

Resolution

Once a new Queue or Topic is created on the broker, the destination is permanently persisted.
Its possible to use jmx to remove old queues and topics using either JConsole or programatically. You invoke removeTopic() or removeQueue() on the main broker mbean object to remove the desired destination.
In order to remove the destination programatically, you can invoke the BrokerViewMBean as shown below:

import javax.management.MBeanServer;
import javax.management.MBeanServerInvocationHandler;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import org.apache.activemq.broker.BrokerViewMBean;
public void removeTopic(String topicName) {
  JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
  JMXConnector connector = null;
  try
  {
   connector = JMXConnectorFactory.connect(url);
   MBeanServerConnection server = connector.getMBeanServerConnection();
   String brokerName = "org.apache.activemq:Type=Broker,BrokerName=localhost";
   BrokerViewMBean broker = (BrokerViewMBean)MBeanServerInvocationHandler.newProxyInstance(server, brokerName, BrokerViewMBean.class, true);
   broker.removeTopic(topicName)

  }
  finally
  {
   try { connector.close(); } catch (Throwable ignore) {}
  }
}

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments