I am using
Jboss as an example here. Probably something similiar should be available with your app. server.
Within the MDB tag definition Jboss provides two tags maximumSize and maximumMessages. Set both to 1 and it should achieve the functionality that you require. For Jboss tag specific details refer
url.
The above replies the first part of your question. Note this will not work in a clustered environment.
For the second portion, easier option is to force both the applications to send messages on the same queue. Using the technique mentioned above you can control the processing in a non-clustered environment.
If that is not possible you will need to develop a locking mechanism using a database. Insert a row in the db for the message being processed and on completion reset the message flag to processed. This would work irrespective if the deployment is clustered or not.