Created
May 20, 2011 21:25
-
-
Save rponte/983841 to your computer and use it in GitHub Desktop.
ActiveMQJMXUtils - trying to purge a fucking queue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Just a tip: you can use the class RemoteJMXBrokerFacade for remote access.
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
It's necessary to add
activemq-web-5.x.jar
to classpath!