views:

77

answers:

3

Say I load messages in a queue from multiple nodes.

Then, one or many nodes are pulling messages from the queue.

Is it possible (or is this normal usage?) that the queue guarantees to not hand out a message to more than one server/node?

And does that server/node have to tell the queue it has completed the operation and the queue and delete the message?

+2  A: 

What messaging/queuing technology are you using ? AMQP can certainly guarantee this behaviour (amongst many others, including pub/sub models)

Brian Agnew
+1  A: 

A message queuing system that did not guarantee to hand out a given message to just one recipient would not be worth the using. Some message queue systems have transactional controls. In that case, if a message is collected by one receiver as part of a transaction, but the receiver does not then commit the transaction (and the message queue can identify that the original recipient is no longer available), then it would be reissued. However, the message would not be made available to two processes concurrently.

Jonathan Leffler
A: 

If you want this in Java - then a JMS compliant messaging system will do what you want - and most messaging systems have a JMS client. You can Use Spring's JmsTemplate for real ease of use too.

With JMS - a message from a Queue will only be consumed by one and only one client - and once it is consumed (acknowledged) - it will be removed from the messaging system. Also when you publish a message using JMS - if its persistent - it will be sent synchronously, and the send() method won't return until the message is stored on the broker's disk - this is important - if you don't want to run the risk of loosing messages in the event of failure.

Rob Davies