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:
You've seen how to create a JMS transacted session earlier in the chapter. The next chapter covers the new message-driven bean and discusses how to use transactions with it. |