与MSMQ相关的几个项目
1.BLL(业务逻辑层) OrderAsynchronous.cs,Order.cs
2.WEB , web.config
3.IMessaging
4.MessageFactory(生成工厂)
5.MSMQMessaging (异步处理实现)
6.Orderprocessor(异步订单处理)
7.IBLLStrategy 同/异步订单策略 接口
相关资料:
http://blog.csdn.net/wangyihust/archive/2006/05/23/751650.aspx
MessageQueue MSDN 帮助 :
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref9/html/T_System_Messaging_MessageQueue_Members.htm
http://ltp.cnblogs.com/archive/2006/04/17/377564.html
配置文件
1.Web.Config
<!-- Order processing options (Asynch/Synch) -->
<add key="OrderStrategyAssembly" value="PetShop.BLL"/>
<add key="OrderStrategyClass" value="PetShop.BLL.OrderAsynchronous"/>--更改
<!-- Asynchronous Order options -->
<add key="OrderMessaging" value="PetShop.MSMQMessaging"/>
<add key="OrderQueuePath" value="FormatName:DIRECT=OS:MachineName/Private$/PSOrders"/>
2.OrderProcessor
最终取出的订单数据还是调用同步机制的类处理:插入数据库,更新库存数据
<add key="WebDAL" value="PetShop.SQLServerDAL"/>
<add key="OrdersDAL" value="PetShop.SQLServerDAL"/>
<!-- Order Asynch/Synch -->
<add key="OrderStrategyAssembly" value="PetShop.BLL" />
<add key="OrderStrategyClass" value="PetShop.BLL.OrderSynchronous" />
<!-- Asynchronous Order options -->
<add key="OrderMessaging" value="PetShop.MSMQMessaging" />
<add key="OrderQueuePath" value="FormatName:DIRECT=OS:MachineName/Private$/PSOrders"/>
项目结构
在项目IMessaging中定义IOrder接口
真正的实现类在MSMQMessaging 项目中,Order实现IOrder接口,同时继承PetShopQueue基类的方法,实现队列的发送和接受功能
MessageFactory 项目依据config文件配置,生成各自的Order类实例,异步取自OrderMessaging
IBLLStrategy 项目提供同步异步策略的接口
在BLL项目中有三个相关类
业务逻辑层的Order类,以及与此相关的OrderAsynchronous.cs,OrderSynchronous.cs异步同步的处理类
其中BLL.Order中方法:
private static PetShop.IBLLStrategy.IOrderStrategy LoadInsertStrategy() { // Look up which strategy to use from config file
//from web.config
//from app.config <!-- Order processing options (Asynch/Synch) -->
<add key="OrderStrategyAssembly" value="PetShop.BLL"/>
<add key="OrderStrategyClass" value="PetShop.BLL.OrderAsynchronous"/>
string path = ConfigurationManager.AppSettings["OrderStrategyAssembly"];
string className = ConfigurationManager.AppSettings["OrderStrategyClass"];
// Using the evidence given in the config file load the appropriate assembly and class
return (PetShop.IBLLStrategy.IOrderStrategy)Assembly.Load(path).CreateInstance(className);
}
依据配置,返回正确的类。
决定是否采取同步还是异步,最终定位在Web项目中的
<!-- Order processing options (Asynch/Synch) -->
<add key="OrderStrategyAssembly" value="PetShop.BLL"/>
<add key="OrderStrategyClass" value="PetShop.BLL.OrderAsynchronous"/>--上
依次决定后继产生的类实例
--学习笔记1
关于其中缓存机制
参考资料:
http://blog.csdn.net/nuaalfm/archive/2007/09/18/1788914.aspx