JMS message "locking"?

S

Scott Balmos

Hi all,

Yet another JMS-related question. Is it possible to have the queue
"lock" a JMS message? What I'm considering is JMS in a point-to-point
setup. My main app server sends control messages to management daemons
on other systems. See previous threads by me in the past few days for
background.

Now, to create a type of pseudo-transaction, based on feedback in the
other threads, my main app server would send a control message to the
queue for the service to control (say, queue MailingListMgmt, which is
watched by the daemons controlling the mailing list servers). This
message would be read by the mailing list management servers, and would
only be consumed (and taken out of the queue) if the operation was
successful.

But if I have, say, three mailing list servers, I only want one server
to attempt the operation at a time. E.g. Box 2 reads the mesasge from
the queue first. I'd like to know if it's possible for Box 2 to "lock"
the message in the queue so that Boxes 1 & 3 don't read it, unless the
operations failed on Box 2 and the message isn't consumed. Then Box 2
would "unlock" the message, letting one of the other boxes attempt the
operations.

Is this possible? I was hoping against setting up separate queues for
each physical machine, as then the app server would have to do all the
management of sending the message to one of the other boxes if the
operation failed, etc.

Thanks for any info!

--Scott
 
J

John Maline

Scott said:
But if I have, say, three mailing list servers, I only want one server
to attempt the operation at a time. E.g. Box 2 reads the mesasge from
the queue first. I'd like to know if it's possible for Box 2 to "lock"
the message in the queue so that Boxes 1 & 3 don't read it, unless the
operations failed on Box 2 and the message isn't consumed. Then Box 2
would "unlock" the message, letting one of the other boxes attempt the
operations.

For queues, this is how it works naturally. A message on a queue will
be received by one consumer only. Regardless of how many consumers
there are.

As for locking/unlocking, there's no such concept. There is the concept
of acknowledging a message. That's where you tell JMS that you've
successfully processed the message. There's an auto-acknowledge mode
where it happens automatically. See
QueueConnection.createQueueSession(). The second parameter indicates if
you're in auto-acknowledge mode or not.

Topics work differently - a copy of the message is received by every
consumer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top