http://www.amazon.com/Enterprise-Integration-Patterns-Designing-Addison-Wesley/dp/0321200683/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1195232579&sr=8-1
This book contains many examples and patterns which are wonderfully handy in messaging.
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.Queue;
public class ChannelPurger extends JmsEndpoint
{
public static void main(String[] args)
{
if (args.length != 1) {
System.out.println("Usage: java ChannelPurger
System.exit(1);
}String queueName = new String(args[0]);
System.out.println("Purging queue " + queueName);
ChannelPurger purger = new ChannelPurger();
purger.purgeQueue(queueName);
}
private void purgeQueue(String queueName)
{
try {
initialize();
connection.start();
Queue queue = (Queue) JndiUtil.getDestination(queueName);
MessageConsumer consumer = session.createConsumer(queue);
while (consumer.receiveNoWait() != null)
System.out.print(".");
connection.stop();
} catch (Exception e) {
System.out.println("Exception occurred: " + e.toString());
} finally {
if (connection != null) {
try {
connection.close();
} catch (JMSException e) {
// ignore
}
}
}
}
}
No comments:
Post a Comment