activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Timothy Bish <tabish...@gmail.com>
Subject Re: Can not remove message from Queue
Date Sat, 06 Jun 2015 16:14:32 GMT
On 06/05/2015 06:53 AM, bhavin.patel wrote:
> Hi Guys, Thanks for taking time to read this.
>
> We have retry mechanism in our queues. We use Camel/ActiveMQ for that.
>
> Requirement is that when any message gets stuck in Retry then user should be
> able to delete that message and hence following messages could start
> processing.
>
> I can read message using QueueBrowser. (Note: I have to use AUTO_ACKNOWLEDGE
> for session as if I use CLIENT_ACKNOWLEDGE then QueueBrowser's enumeration
> gets stuck in hasMoreElement()).
>
> But I can read those message again and again means using AUTO_ACKNOWLEDGE
> doesn't seems to remove messages from queue.
>
> While removing message I'm using following code:
>
> public void removeMessage(final String messageID) throws JMSException {
>
>         log.info("Removing message from queue. Message Id: " + messageID);
>
>         ActiveMQConnection connection = (ActiveMQConnection)
> unpooledActiveMqConnectionFactory.createConnection();
>         connection.setOptimizeAcknowledge(false);
>         connection.start();
>         ActiveMQSession session = (ActiveMQSession)
> connection.createSession(transacted, Session.CLIENT_ACKNOWLEDGE);
>
>         // Get all queues
>         Set<ActiveMQQueue> amqs =
> connection.getDestinationSource().getQueues();
>
>         Iterator<ActiveMQQueue> queues = amqs.iterator();
>
>         while (queues.hasNext()) {
>
>             ActiveMQQueue queue_t = queues.next();
>
>             if (isValidQueue(queue_t.getPhysicalName())) {
>                 QueueReceiver receiver = session.createReceiver(queue_t,
> "JMSMessageID='" + messageID + "'");
>                 connection.start();
>                 Message message = receiver.receiveNoWait();
>                 if (message != null) {
>                     message.acknowledge();
>                 }
>                 receiver.close();
>                 log.info("Message removed from queue. Message Id: " +
> messageID);
>             }
>         }
>
>         session.close();
>         connection.close();
>     }
>
> Even AUTO_ACKNOWLEDGE for removing doesn't seems to do anything.
> After this if I read messages back again I get all messages. REMOVE never
> seems to do anything.
> Any suggestion. I have look at quite a few so called solutions online but
> none works.
>
> I GET NO EXCEPTION in any logs.
>
> could use some help.
> Thanks
> Bhavin
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/Can-not-remove-message-from-Queue-tp4697351.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
Is your session transacted?  If so then you need to commit the TX
otherwise when you close the session it will automatically rollback the
TX and nothing is removed.

-- 
Tim Bish
Sr Software Engineer | RedHat Inc.
tim.bish@redhat.com | www.redhat.com 
twitter: @tabish121
blog: http://timbish.blogspot.com/


Mime
View raw message