
How This Sample Was Designed and Why
This sample was designed to illustrate how to use BAM to store information from an application that is not a BizTalk orchestration. While the application is simple, it illustrates several aspects of BAM that you are likely to use in a production application. These include the following:
- Multiple threads that contribute to a single activity
- Creating a relationship between two activities
- Using a continuation to allow the same activity to be accessed with different IDs
The BAM API sample consists of three main classes: one to process purchase orders, one to process shipments, and one to process invoices. Each class has a RunOnce method that retrieves a message from a queue, and then processes the message. Each class also has a Run method that continually calls the RunOnce method.
The RunOnce method of the PoApplication class does the following:
- Creates an XML message that represents a purchase order.
- Begins a BAMApiPo activity and adds to the activity information about the purchase order and when it was received.
- Arbitrarily approves or rejects the purchase order.
- Updates the BAMApiPo activity to record the status of the purchase order (accepted or rejected).
- If the purchase order was accepted, the RunOnce method also does the following:
- Creates an XML message to represent a package to be shipped, and adds the message to the queue of shipments.
- Adds the XML message that represents the purchase order to the queue of purchase orders to be included in an invoice.
- Enables continuation for the BAMApiPo activity.
- Ends the BAMApiPo activity.
The RunOnce method of the ShipmentApplication class does the following:
- Retrieves from its queue an XML message that represents a package to be shipped.
- Updates the BAMApiPo activity to record the time that the package was shipped.
- Ends the BAMApiPo activity.
The RunOnce method of the InvoiceApplication class does the following:
- Retrieves from its queue an XML message that represents a purchase order to be invoiced.
- Begins a BAMApiInvoice activity.
- Creates a BAM relationship between the BAMApiInvoice activity and the BAMApiPo activity for the purchase order that is being invoiced.
- Adds to the BAMApiPo activity information about the invoice and the time it was created.
- After an arbitrary delay to simulate waiting for the invoice to be paid, adds to the BAMApiInvoice activity the time the invoice was paid.
- Ends the BAMApiInvoice activity.
The Main method of the MainApp class initializes the application. It does the following:
- Creates a DirectEventStream object.
- Starts several threads, and calls the Run method of the POApplication object in each thread.
- Starts several threads, and calls the Run method of the ShipmentApplication object in each thread.
- Starts several threads, and calls the Run method of the InvoiceApplication object in each thread.
The Global class defines constants that are used by the sample application, such as the number of threads to create and the percentage of purchase orders to reject.
In addition to the Visual Studio solution, the sample also contains a Microsoft Excel file that defines the activities.