Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMS transaction

Database transactions is a familiar concept.

try {
  ...
  ..
  updateDB()
  ..
  ...
  commit();
} catch error {
  rollback();
}

if any error occurs any changes made by updateDB will be discarded.

I wanted to know what a message queue transaction rollback will undo.

try{
  ...
  ...
  //EDIT: swapped the order of receive and send
  Message m = queue1.receiveMessage(..)
  ..
  ..
  queue2.sendMessage(..)
  ..
  ..
  commit();
} catch error {
  rollback();
}

specifically, what will rollback do

  1. cancel the sending of message
  2. un-receive the message ie put back the received message back to queue

or am i stretching the database tx analogy too far.

thanks

EDIT: i am not implying the send and receive operations are related. i just wanted to say there are two operations that change the state of the message broker -- receive will take out a message from the queue which will be unavailable for other consumers if there were any.

like image 956
mzzzzb Avatar asked Dec 15 '12 07:12

mzzzzb


People also ask

What is a JMS transaction?

The JMS API Session interface provides commit and rollback methods that you can use in a JMS client. A transaction commit means that all produced messages are sent and all consumed messages are acknowledged.

What is JMS used for?

The Java Message Service (JMS) makes it easy to develop enterprise applications that asynchronously send and receive business data and events. It defines a common enterprise messaging API that is designed to be easily and efficiently supported by a wide range of enterprise messaging products.

Can a JMS session be transactional?

JMS applications can run local transactions by first creating a transacted session. An application can commit or roll back a transaction.

How do I create a transactional in JMS?

To make a session transactional set transacted=true flag on the JMS endpoint and configure a transactionManager on the Component or Endpoint.


1 Answers

Rollback of the send is straight forward, the message will not be put to queue2.

Rollback of the receive will typically put the message back on the queue (queue1). Depending on your JMS provider setup and configuration, the message will be redelivered a number of times. If the transaction rolls back too many times (too many is configurable) it will be put to a "Backout queue" (or dead letter queue), so that it will not block the queue for other messages. A backed out message typically needs some manual error handling.

like image 67
Petter Nordlander Avatar answered Sep 19 '22 04:09

Petter Nordlander