Using Orchestration Transactions (Short, Long, andTimed)In Chapter 5, you created an orchestration that processes the FundInvestors document.You used a Decision shape to determine whether your COM+ component completed successfully, but because the orchestration didn't have any transactional support, the actions that were performed couldn't be rolled back in the event of failure. Bob wants Mike to build a trading workflow that can process the buy and sell orders for the mutual fund companies, but he wants the trading XLANG Schedule to support transactions so that when an error occurs, any changes that have been made will automatically be rolled back to maintain the integrity of the data in the system. Let's take a quick look at transactions before tackling this assignment.A transaction is a group of operations that are processed as a single unit. In the computer world, transactions follow these four rules, collectively known as the ACID rules:
Types of TransactionsIn BizTalk Orchestration, you can make your Action-shape implementations participate in a transaction in one of two ways: Run your XLANG Schedule as a traditional transactional COM+ component or as an XLANG Schedule transaction that is specific to BizTalk Orchestration.When making an XLANG Schedule run as a COM+ component, external COM+ components can start such a XLANG Schedule as if it were a COM+ component.The transactional behavior of this type of XLANG Schedule is the same as a COM+ component.To configure an XLANG Schedule to run as a COM+ component, open the properties page of the Start shape at the top of the workflow, and for the Transaction model field, select "Treat the XLANG Schedule as a COM+ Component"(see Figure 10-1).Figure 10-1. Configuring the transaction model for the orchestrationThere are four transaction activation options available for this type of XLANG Schedule (which are the same as for COM+ components):
The other transaction model for the schedule is "Include transaction within the XLANG Schedule". When selecting this transaction model, the actions within the schedule can participate in a transaction by locating them inside a Transaction shape. The four transaction activation types are also available for this transaction model.When it comes time to choose which transaction model to use for your schedule, there are a number of factors to consider. In terms of performance, running the schedule as a COM+ component is much faster than using the other model. However, when running as an XLANG-style transaction, your schedule will be able to support Distributed Transaction Coordinator (DTC) style transactions, long-term transactions, timed transactions, and nested transactions. I'll discuss these transaction types later in this chapter. The COM+ transaction model only supports DTC-style transactions.In fact, the Transaction shapes aren't even allowed in an orchestration unless the orchestration's transaction model setting is "Include Transaction within the XLANG Schedule" on the Begin shape. If the orchestration isn't configured this way and contains transactions, it will cause a compile error when you try to compile it into an .skx file.NOTE When you choose to treat the schedule as a COM + component, you can't use the Transaction shape on the schedule, or an error will occur when compiling the schedule.The Transaction shape is exclusively used when choosing the other transaction model ("Include transaction in the XLANG Schedule").NOTE DTC provides services to manage transactions that span different transactional sources. COM+ replies on DTC for its transactional support. For example, by using DTC, a COM+ component can write to a database and MSMQ, two separate transactional resources, in a single transaction.With XLANG-style transactions, your schedule can also define actions to be taken in event of a transaction failure. This feature isn't available in COM+-style transactions. A schedule with XLANG-style transactions is shown in Figure 10-2.Figure 10-2. A schedule with XLANG-style transactionTo create a transaction inside another transaction, you need to first drag and drop a Transaction shape from the flowchart panel onto the Business Process page (which creates a new transaction), and then drag another transaction into the boundary of the first Transaction shape. You must make sure that all four sides of the second (inner) Transaction shape fit inside the four sides of the first (outer) Transaction shape, or the inner transaction won't be considered nested inside the outer one. To verify whether the transaction is nested properly, you can drag the outer Transaction shape around a bit-if the inner Transaction shape moves with the outer one, the inner transaction is properly nested. You can resize the Transaction shapes so that one can fit inside another.NOTE If you delete the outer Transaction shape, the inner transaction, along with the shapes inside it, is deleted as well. If you want to keep the inner Transaction shape, make sure you move the inner transaction outside of the boundary of the outer one, unnesting the inner one, before deleting the outer transaction.Short-Lived TransactionsLet's come back to Bob's trading XLANG Schedule. He wants the schedule to perform the actions shown in Figure 10-3.Figure 10-3. Actions involved in Bob's trading scheduleFive actions are involved in this trade schedule:
Bob already has a document specification for this schedule, named Trade, defined in XML editor (see Figure 10-4).Figure 10-4. Trade document specificationA sample trade from a client would look like this:
<Trade> <FundCompany>Henry Fonda Inc.</FundCompany> <TradeItems> <TradeItem> <Ticker>IBM</Ticker> <TransactionType>Buy</TransactionType> <Share>10000</Share> <Price/> <OrderType>Market Order</OrderType> <ExecutionStatus/> </TradeItem> <TradeItem> <Ticker>MSFT</Ticker> <TransactionType>Buy</TransactionType> <Share>15000</Share> <Price>65.50</Price> <OrderType>Limit Order</OrderType> <ExecutionStatus/> </TradeItem> </TradeItems> <TotalTransactionAmount/></Trade>The <ExecutionStatus> field will contain the execution information for each individual stock transaction in the document. Its content will be filled by Bob's trading component, and it will contain information on whether a specific transaction completed or not. For example, if the limit price isn't reached, the transaction won't take place; in such a case, the trading component will insert "Limited price is not met" in the field to indicate that this particular order wasnot processed. The trading component will also fill the <TotalTransactionAmount> and <ExecutionStatus> fields under each TradeItem record. The TotalTransactionAmount is the total dollar amount for each individual trade that is completed in the document.In this trade schedule, you want to use XLANG-style transactions. You'll use short-term transactions in this schedule. Later in this chapter, I'll show you how to work with long-term and timed transactions, but for now, let's find out what advantages can be gained by making actions transactional.