activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leonardo K. Shikida" <shik...@gmail.com>
Subject trying to consume (remove) a message
Date Tue, 16 Jul 2013 15:10:07 GMT
Hi

I am trying to remove (consume) a message from the queue, without success.

Here's my code and the output

public boolean remove(String jmsMessageID) throws JMSException{

boolean messageConsumed = false;

Connection connection = null;
Session session = null;
try {
ConnectionFactory connectionFactory = this.baseService.getConnectionFactory();
connection = connectionFactory.createConnection();
connection.start();

// Create a Session
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

QueueBrowser browser = session.createBrowser(this.baseService.getQueue());
   Enumeration<?> messagesInQueue = browser.getEnumeration();

   while (messagesInQueue.hasMoreElements()) {
    Message queueMessage = (Message) messagesInQueue.nextElement();
    System.out.println("Enqueued > "+queueMessage.getJMSMessageID());
   }

   System.out.println("Trying to delete > "+jmsMessageID);

Queue queue = this.baseService.getQueue();
MessageConsumer consumer =
session.createConsumer(queue,"JMSMessageID='"+jmsMessageID+"'");
Message message = null;
while((message = consumer.receiveNoWait()) != null){
System.out.println("Consumed > "+message);
messageConsumed = true;
}

} finally {
if (session != null)
session.close();
if (connection != null)
connection.close();
}

return messageConsumed;
}

>>>>>>>

Enqueued          > ID:7612866413.mydomain.com-58510-1373986917055-5:1:35:1:1
Enqueued          > ID:7612866413.mydomain.com-58510-1373986917055-5:1:61:1:1
Enqueued          > ID:7612866413.mydomain.com-58510-1373986917055-5:1:63:1:1
Trying to delete  > ID:7612866413.mydomain.com-58510-1373986917055-5:1:63:1:1

(never enter into System.out.println("Consumed > "+message);)

Am I missing something here?

[]

Leo

Mime
View raw message