Skip to content

Instantly share code, notes, and snippets.

@rponte
Created May 20, 2011 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rponte/983841 to your computer and use it in GitHub Desktop.
Save rponte/983841 to your computer and use it in GitHub Desktop.
ActiveMQJMXUtils - trying to purge a fucking queue
package base.jms;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.web.BrokerFacadeSupport;
import org.apache.activemq.web.LocalBrokerFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class ActiveMQJMXUtils {
BrokerFacadeSupport facade;
@Autowired
public ActiveMQJMXUtils(BrokerService brokerService) {
this.facade = new LocalBrokerFacade(brokerService);
}
public void cleanUp(String queueName) {
try {
facade.purgeQueue(new ActiveMQQueue(queueName));
long size = getQueueSize(queueName);
if (size > 0)
throw new IllegalStateException("It was not possible to clean up the queue '" + queueName + "'.");
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
public long getQueueSize(String queueName) {
try {
QueueViewMBean queue = facade.getQueue(queueName);
return (queue != null ? queue.getQueueSize() : 0);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
}
@areddy7021
Copy link

Hi , Can i have a brokerservice instance for the remote broker instead of local host ? I was just trying to get the existing broker service object from the running remote broker , please share me your thoughts on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment