jms - Take first message to arrive on one of 2 queues -


i have application i'd consume messages queue a, if queue empty, i'd consume messages queue b instead of sitting idle. ever want process 1 message @ time, , if consumer busy processing message (from either queue), other pending messages (on either queue) should remain on queue until consumer idle again (this gives other consumers chance process new message).

so, example, if message arrives on either queue or queue b while consumer idle (waiting), consumer picks up. if message arrives on either queue while consumer processing message, nothing happens until consumer has finished processing current message. , if message available on both queue , queue b, consumer prefers pick message queue a.

edit: i'd equally happy informed messages available consume on both & b, , implement own logic choose 1 want pull queue.

subscribing both queues @ once in separate threads doesn't appear work because:

  • if message m arrives on queue a, consumer have unsubscribe queue b while it's processing message m, resubscribe once message m handled. otherwise, if message arrives on queue b, might picked , dispatched simultaneously - don't want handle more 1 message @ time.
  • if message arrives on both queues @ once (or message available on both queues when consumer starts or finishes processing previous message), it's possible both messages picked before consumer has chance unsubscribe queue b. if happens i'd have roll 1 of messages back, if happens message exceed rollback count , moved failure queue.

ideally i'd generalise n queues case. i'm interested in solutions ideally work via jms, if have use ibm mq-specific api that's ok too. there usage pattern, or library, achieve this? there alternative queueing approaches/techniques/technologies allow it?

pulling messages off queues , putting them onto single queue no-go; need able clear individual queues independently, , different consumers may subscribe different subsets of n queues.

i don't know if big change code, have thought of adding spring framework , spring integration in project? such issues describe handled there.

this problem solved 2 endpoints event driven consumers on 2 queues , single thread pool.

http://www.eaipatterns.com/eventdrivenconsumer.html

http://en.wikipedia.org/wiki/thread_pool_pattern

[edit]

if want message stay in queue until thread released can follow pattern of polling consumer

http://www.eaipatterns.com/pollingconsumer.html

which can chose wish queue request message first. keep in mind technique if system processes messages faster arrive, experience redundant polls queues.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -