PetShop中的OrderStrategy和System.Transactions
Asynchronous Order Placement Setup Instructions
1. Add a new private queue for Pet Shop called “PSOrders”
2. Modify web.config:
a.Change the OrderStrategyClass key to OrderAsynchronous
<add key=”OrderStrategyClass” value=”PetShop.BLL.OrderAsynchronous”/>
b.Change the MachineName in the following line to your MSMQ computer name.
<add key=”OrderQueuePath” value=”FormatName:DIRECT=OS:MachineName\Private$\PSOrders”/>
3. Modify app.config in the OrderProcessor project:
Change the MachineName in the OrderQueuePath key:
<add key=”OrderQueuePath” value=”FormatName:DIRECT=OS:MachineName\Private$\PSOrders”/>
同步定单处理 和 System.Transactions
同步定单处理中的 Order.Insert() 方法使用 System.Transactions 插入一个定单并更新库存。
通过添加对 System.Transaction 命名空间的引用,并将定单插入方法和库存减少方法包装在
TransactionScope 内,
–多线程
OrderProcessor会使用多线程从Message queue中读取order,
注意,并没有任何防止竞争的机制,莫非message queue可以做到这一点?
–Transaction
OrderProcessor使用了TransactionScope,注意设置TransactionScope的
Consistent或调用TransactionScope的Complete()
System.Transactions介绍
http://blog.joycode.com/kaneboy/archive/2005/02/15/44356.aspx
Introducing System.Transactions in .NET Framework 2.0
http://msdn.microsoft.com/msdntv/episode.aspx?xml=episodes/en/20050203NETMC/manifest.xml
