我需要使用java程序从ActiveMQ中删除QUEUE中的消息。我在谷歌搜索但我没有找到任何适当的例子。我能够获得QUEUE中的所有消息。一旦完成提取,我需要删除队列中的所有消息。
我正在使用以下代码来获取所有消息:
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
ActiveMQConnection connection = (ActiveMQConnection)connectionFactory.createConnection();
// DestinationSource ds = connection.getDestinationSource();
System.out.println("DestinationSource created");
QueueSession queueSession = connection.createQueueSession(true, Session.CLIENT_ACKNOWLEDGE);
connection.start();
System.out.println("session Created");
Queue queue = queueSession.createQueue(QUEUENAME);
System.out.println("Connected");
QueueBrowser browser = queueSession.createBrowser(queue);
Enumeration<?> messagesInQueue = browser.getEnumeration();
System.out.println("messagesInQueue ==>"+messagesInQueue);
//System.out.println(""+messagesInQueue.hasMoreElements());
int size = 0;
while (messagesInQueue.hasMoreElements())
{
Message queueMessage = (Message) messagesInQueue.nextElement();
System.out.println(queueMessage.getJMSMessageID());
size = size+1;
System.out.println(queueMessage);
TextMessage text = (TextMessage) queueMessage;
System.out.println(new Date()+"Message is : " + text.getText());
}
System.out.println("Size===>"+size);
有人请分享任何示例java代码以删除QUEUE中的消息......