Programmatically purge() a queue

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Programmatically purge() a queue

centis
I am trying to find an example of purging a Queue from Java.  Can someone point me to someting besides, "Using JMX..." :)  I just need a way to clear out the existing queues before my regression tests run.

Thanks!
CB
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically purge() a queue

atooni
hmmm,

why not start the broker with the option  
"deleteAllMessagesOnStartup=true" for the test ?

Best regards
Andreas

On Aug 11, 2009, at 7:40 PM, centis wrote:

>
> I am trying to find an example of purging a Queue from Java.  Can  
> someone
> point me to someting besides, "Using JMX..." :)  I just need a way  
> to clear
> out the existing queues before my regression tests run.
>
> Thanks!
> CB
>
> --
> View this message in context: http://www.nabble.com/Programmatically-purge%28%29-a-queue-tp24923382p24923382.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Reply | Threaded
Open this post in threaded view
|

Re: Programmatically purge() a queue

Bruce Snyder
In reply to this post by centis
On Tue, Aug 11, 2009 at 1:40 PM, centis<[hidden email]> wrote:
>
> I am trying to find an example of purging a Queue from Java.  Can someone
> point me to someting besides, "Using JMX..." :)  I just need a way to clear
> out the existing queues before my regression tests run.

Oddly, the solution is to use JMX; just programatically instead of via
Jconsole. Here's an example:

// The ActiveMQ JMX domain
String amqDomain = "org.apache.activemq";

// The parameters for an ObjectName
Hashtable<String, String> params = new Hashtable<String, String>();
params.put("Type", "Queue");
params.put("BrokerName", brokerName);
params.put("Destination", queueName);

// Create an ObjectName
ObjectName queueObjectName = ObjectName.getInstance(amqDomain, params);

// Create a proxy to the QueueViewMBean
QueueViewMBean queueProxy = (QueueViewMBean)
broker.getManagementContext().newProxyInstance(queueObjectName,
QueueViewMBean.class, true);

// Purge the queue
queueProxy.purge();


Bruce
--
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

ActiveMQ in Action: http://bit.ly/2je6cQ
Blog: http://bruceblog.org/
Twitter: http://twitter.com/brucesnyder
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically purge() a queue

centis
Bruce,

Thanks for your reply!  I've seen several examples like that the problem I am having is the "broker".  I'm not using an embedded broker, the problem I'm having is getting the "broker" object.  I'm poking around in the samples but I don't see an example that doesn't use an embedded broker.

CB

<quote author="bsnyder">
On Tue, Aug 11, 2009 at 1:40 PM, centis<centis_biks@hotmail.com> wrote:
>
> I am trying to find an example of purging a Queue from Java.  Can someone
> point me to someting besides, "Using JMX..." :)  I just need a way to clear
> out the existing queues before my regression tests run.

Oddly, the solution is to use JMX; just programatically instead of via
Jconsole. Here's an example:

// The ActiveMQ JMX domain
String amqDomain = "org.apache.activemq";

// The parameters for an ObjectName
Hashtable<String, String> params = new Hashtable<String, String>();
params.put("Type", "Queue");
params.put("BrokerName", brokerName);
params.put("Destination", queueName);

// Create an ObjectName
ObjectName queueObjectName = ObjectName.getInstance(amqDomain, params);

// Create a proxy to the QueueViewMBean
QueueViewMBean queueProxy = (QueueViewMBean)
broker.getManagementContext().newProxyInstance(queueObjectName,
QueueViewMBean.class, true);

// Purge the queue
queueProxy.purge();


Bruce
--
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

ActiveMQ in Action: http://bit.ly/2je6cQ
Blog: http://bruceblog.org/
Twitter: http://twitter.com/brucesnyder

</quote>