If you only care about messages that are already in the queue then I
recommend using receiveNoWait() [1].


Justin

[1]
https://docs.oracle.com/javaee/7/api/javax/jms/MessageConsumer.html#receiveNoWait--

On Sat, Sep 21, 2024 at 2:03 PM John Lilley
<john.lil...@redpointglobal.com.invalid> wrote:

> I am trying to build a utility for purging a queue of all messages
> matching a filter.  The purpose is to remove “job start” messages that have
> been aborted before they were consumed and started.
>
> To this end I have code like:
>
> Destination destination = session.createQueue(queueName);
> String selector = propertyName + "='" + propertyValue + "'";
> var consumer = session.createConsumer(destination, selector);
> Message message = null;
> while ((message = consumer.receive(PURGE_TIMEOUT_MS)) != null) {
>     result.add(message);
> }
>
> I am unsure about PURGE_TIMEOUT_MS.  I only care about messages that are
> already in the queue.  Does this mean that receiveImmediately() would
> always get a message if one is in the queue?  Or can there be a small delay
> while (I am guessing) some internal consumer waits for a message to be
> delivered asynchronously and then signals a semaphore?  If so, how long
> should I wait to be sure?
>
> Thanks
> john
>
>
> [rg] <https://www.redpointglobal.com/>
>
> John Lilley
>
> Data Management Chief Architect, Redpoint Global Inc.
>
> 34 Washington Street, Suite 205 Wellesley Hills, MA 02481
>
> M: +1 7209385761<tel:+1%207209385761> | john.lil...@redpointglobal.com
> <mailto:john.lil...@redpointglobal.com>
>
>  PLEASE NOTE: This e-mail from Redpoint Global Inc. (“Redpoint”) is
> confidential and is intended solely for the use of the individual(s) to
> whom it is addressed. If you believe you received this e-mail in error,
> please notify the sender immediately, delete the e-mail from your computer
> and do not copy, print or disclose it to anyone else. If you properly
> received this e-mail as a customer, partner or vendor of Redpoint, you
> should maintain its contents in confidence subject to the terms and
> conditions of your agreement(s) with Redpoint.
>

Reply via email to