我使用 MSMQ 作为提供异步 SOA 的一种方式。请参考下面的代码,因为它很难解释。我试图找出最好的方法来做到这一点。
//another method reads off MSMQ and passes the Message into this method
public void ReadMSMQAndAction(Message m)
{
var e = m.Entity;
/* this is really bad, but i some how still need some
* kind of traffic cop to direct action */
switch typeof(m.Entity)
case Order.GetType()
switch e.Action
case "SAVE"
//todo OrderRepo Save
}
//Message gets searlized and put into MSMQ
public class Message<T>
{
public T Entity { get;set; }
/* should this be string?
* or some kind of rule i.e. "ClassName:MethodName" etc? */
public string Action { get;set; }
}
public class OrderRepo
{
public void Save(Order o) { /* todo */ }
public void Delete(Order o) { /* todo */ }
public void Update(Order o) { /* todo */ }
}
随着代码变得越来越复杂,将很难管理。欢迎任何建议!