JMS - how to delete a queue
this is about how you can delete all messages in a jms queue
We have to set the Properties for the jboss application server or whatever you are using
p.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
p.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
p.setProperty("java.naming.provider.url","localhost:1099");
as next we have to create the initial context
InitialContext ctx = new InitialContext(p);
then we obtain all the needed queues and factorys
QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("QueueConnectionFactory");
QueueConnection qc = qcf.createQueueConnection();
Queue queue = (Queue) ctx.lookup("the queue");
QueueSession qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueReceiver receiver = qs.createReceiver(queue);
we have to start our connection, or nothing is working!
qc.start();
then we receive all messages until we get null as return value, than we know the queue is empty
while (receiver.receiveNoWait() != null) {
//do nothing
}
and we are done!
p.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
p.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
p.setProperty("java.naming.provider.url","localhost:1099");
as next we have to create the initial context
InitialContext ctx = new InitialContext(p);
then we obtain all the needed queues and factorys
QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("QueueConnectionFactory");
QueueConnection qc = qcf.createQueueConnection();
Queue queue = (Queue) ctx.lookup("the queue");
QueueSession qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueReceiver receiver = qs.createReceiver(queue);
we have to start our connection, or nothing is working!
qc.start();
then we receive all messages until we get null as return value, than we know the queue is empty
while (receiver.receiveNoWait() != null) {
//do nothing
}
and we are done!
Created by
zwluxx
Last modified 2005-12-05 04:27 AM
Last modified 2005-12-05 04:27 AM