On Sun, Aug 9, 2009 at 8:32 AM, amp834 <[email protected]> wrote: > > I'm using ActiveMQ to "Submit a job" to queue "Job53" (a queue for each job), > with (say) 500 subtasks, and want to know when the 500 items have been > processed completely. I thought of creating a queue just for that job, > writing 500 messages to it, and when the 500 messages have been processed, > the job is done. > > Is there a way to tell if a queue is empty? (no messages in the queue, no > messages that a consumer has taken but has not finished processing)? > > I found an old post, but it's so old that I thought I'd ask the question > again. > http://www.nabble.com/Query-the-number-of-messages-from-a-Queue-to3652780.html#a3653404
IMO, you shouldn't use messaging with a client/server mind set of querying the message broker. Instead, you should utilize a messaging-based approach to the problem. I suggest using asynchronous messaging for such designs whereby messages are sent to another queue to indicate that a job/message has been processed. By sending a message to a different queue upon completion of such processing, the client can poll for messages on that queue and know immediately when the processing is complete. There's a pattern in the EIP book that covers event messages, see the following: http://eaipatterns.com/EventMessage.html You could also consider using request/reply messaging on a per message basis. For each request message that is sent to one queue, processing is completed a reply message is sent to a different queue to indicate that processing of that message has completed. The EIP book has an example for request/reply style of messaging available here: http://eaipatterns.com/RequestReplyJmsExample.html There are many such patterns in the EIP book for messaging-based design. Additionally, you may want to take a look at Apache Camel, an integration framework that is designed to provide ease of implementation for the EIP patterns. Also, Camel integrates easily with ActiveMQ and many other technologies: http://camel.apache.org/ Bruce -- perl -e 'print unpack("u30","D0G)u8...@4vyy9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*" );' ActiveMQ in Action: http://bit.ly/2je6cQ Blog: http://bruceblog.org/ Twitter: http://twitter.com/brucesnyder
