How to hold a queue of messages and have a group of working threads without polling?
Posted
by Mark
on Stack Overflow
See other posts from Stack Overflow
or by Mark
Published on 2010-03-18T12:31:54Z
Indexed on
2010/05/08
11:18 UTC
Read the original article
Hit count: 222
I have a workflow that I want to looks something like this:
/ Worker 1 \ =Request Channel= -> [Holding Queue|||] -> Worker 2 -> =Response Channel= \ Worker 3 /
That is:
- Requests come in and they enter a FIFO queue
- Identical workers then pick up tasks from the queue
- At any given time any worker may work only one task
- When a worker is free and the holding queue is non-empty the worker should immediately pick up another task
- When tasks are complete, a worker places the result on the
Response Channel
I know there are QueueChannel
s in Spring Integration, but these channels require polling (which seems suboptimal). In particular, if a worker can be busy, I'd like the worker to be busy.
Also, I've considered avoiding the queue altogether and simply letting tasks round-robin to all workers, but it's preferable to have a single waiting line as some tasks may be accomplished faster than others. Furthermore, I'd like insight into how many jobs are remaining (which I can get from the queue) and the ability to cancel all or particular jobs.
How can I implement this message queuing/work distribution pattern while avoiding a polling?
Edit: It appears I'm looking for the Message Dispatcher pattern -- how can I implement this using Spring/Spring Integration?
© Stack Overflow or respective owner