activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Posta <christian.po...@gmail.com>
Subject Re: trying to consume (remove) a message
Date Tue, 16 Jul 2013 19:25:13 GMT
Try giving a brief moment between creating your consumers and the call to
receiveNoWait():

            MessageConsumer consumer =
                    session.createConsumer(queue, "JMSMessageID='" +
jmsMessageID + "'");
            Message message = null;
            Thread.sleep(500);
            while ((message = consumer.receiveNoWait()) != null) {
                System.out.println("Consumed > " + message);
            }

Alternatively, use consumer.receive(500)


On Tue, Jul 16, 2013 at 11:10 AM, Leonardo K. Shikida <shikida@gmail.com>wrote:

> 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
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message