Producer looks at each message type and routes to any ArrayBlockingQueue
based on availability of space in that Queue
. There are only two types of messages Type 1 or Type 2. A given queue can contain only one type of message. I want to build a system which can have 'm' queues where some of them will contain Type 1 messages, and the rest will contain Type 2 messages. Now each queue can have one or more consumers reading from it. Mapping of Queue
to consumer is 1:n. Each consumer will consume from exactly 1 queue.
Now, the functionality I want is this:
- If there is even one queue with space in it, the producer should
put()
a message into that queue. Producer should block onput()
only if all queues are full. - As long as there is a message in a queue, all consumers that are waiting on a given queue should be able to
take()
from the queue and get a message of their own. - No message should be processed by multiple consumer threads.
Is this possible and elegant with ArrayBlockingQueue
? Or is there a better solution for this problem?