Using Transactions with JMS

   

You learned about the Session interface back in the "The JMS Interfaces" section earlier. When using a transacted session, all messages that are produced and sent are performed as a unit of work. If anything happens that causes a need to roll back the transaction, all messages that are produced within that transaction are destroyed , and all the messages that are sent are recovered. This allows a client to treat a group of messages as an atomic unit. Either all of them succeed or none of them do.

You can use the session's commit or rollback methods to cause a session to succeed or fail, respectively. After a transaction is complete by calling either of the two methods , a new transaction is automatically created for the client.

There are three different methods for using a transaction in your JMS application:

  • Use a JMS transacted session

  • If you are using EJB with JMS, you should use a Java Transaction API (JTA) user transaction in a nontransacted JMS Session

  • Use message-driven beans

You've seen how to create a JMS transacted session earlier in the chapter.

Using user transactions with the JTA is beyond the scope of this chapter and is covered briefly later in the book. For more information on user transactions, see Chapter 12, "Transactions."

The next chapter covers the new message-driven bean and discusses how to use transactions with it.



Special Edition Using Enterprise JavaBeans 2.0
Special Edition Using Enterprise JavaBeans 2.0
ISBN: 0789725673
EAN: 2147483647
Year: 2000
Pages: 223

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net