[jboss-user] [JBoss Messaging] - consume message inside a QueueBrowser loop
everson .
do-not-reply at jboss.com
Sat Oct 22 16:42:23 EDT 2011
everson . [http://community.jboss.org/people/everjava] created the discussion
"consume message inside a QueueBrowser loop"
To view the discussion, visit: http://community.jboss.org/message/633148#633148
--------------------------------------------------------------
I would like after do something consume/delete/take out the message from queue, but I can't ....
I have 4 messages on queue and I want consume just one
QueueConnectionFactory factory = (QueueConnectionFactory) getInitialContext().lookup("/ConnectionFactory");//java:/ConnectionFactory
Queue queue = (Queue) getInitialContext().lookup("queue/MyQueue");
connection = factory.createQueueConnection();
session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
*QueueBrowser* queueBrowser = session.createBrowser(queue);
Enumeration<ObjectMessage> messages = queueBrowser.getEnumeration();
while (messages.hasMoreElements()) {
ObjectMessage objectMessage = (ObjectMessage) messages.nextElement();
Person p = (Person) objectMessage.getObject();
System.err.println(p.getId());
//do something....
//* after do something take out the message from queue
}
* I tried code below, but i got error
QueueReceiver receiver = session.createReceiver(queue, "JMSMessageID="+objectMessage.getJMSMessageID());
MessageConsumer consumer = session.createConsumer(queue, "JMSMessageID="+objectMessage.getJMSMessageID());
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/633148#633148]
Start a new discussion in JBoss Messaging at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2042]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20111022/c02ac232/attachment.html
More information about the jboss-user
mailing list