In our backend there are several services that send and receive messages via JMS with Apache ActiveMQ. Each service has a single session to the ActiveMQ broker. We now want to do the following (pseudo code):
Service s1:
Message m = createMessage("s2","Hello World")
sendMessage(m)
try {
Message answer = commit()
...
} catch (TransactionFailedException e){
...
}
Service s2:
onMessageReceive:
try {
Message m = getReceivedMessage()
Message answer = doSomeStuff()
send(answer)
} (Exception e) {
rollback()
}
The commit obviuosly has to block until the answer arrives or the transaction failes. It should also be possible that service s2 creates a new nested transaction because s2 is sending a message to another service. How can transactions from ActiveMQ be used to achieve this behaviour? There are some examples available but in these examples transactions are merely used as a batch mechanism to send messages.