当前位置:编程学习 > C#/ASP.NET >>

MSMQ的问题

这几天我在研究PetShop4.0,其中搞不懂MessageQueueTransactionType的使用,请哥哥们帮忙解惑一下。
在PetShop4.0的数据访问层中,利用MSMQ 技术将订单传输给订单处理程序。PetShop4.0使用的是事务性消息队列,在发送和接受消息方法中,均对消息队列的事务类型使用了MessageQueueTransactionType枚举值。

其中使用的枚举值是Automatic和Single,用MSDN查了查其解释如下:
Automatic:用于 Microsoft Transaction Server (MTS) 或 COM+ 1.0 服务的事务类型。如果已有 MTS 事务上下文,将在发送或接收消息时使用它。
Single:用于单个内部事务的事务类型。 

PetShop4.0中,接受消息使用的是Automatic类型,发送消息使用的是Single类型。
而源码注释说二者的区别是:接受消息的方法涉及分布式事务并且需要自动事务类型,所以用Automatic;发送消息的方法不涉及分布式事务并且使用Single类型优化性能,所以使用Single类型。

我实在迷惑了,为什么接受消息的方法就分布式事务了,而发送就不是分布式了,是怎么区别这个的?如果发送和接受消息方法中不定义消息队列的事务类型,可以吗??
--------------------编程问答-------------------- 代码是下面这个:

public new OrderInfo Receive()
{
// This method involves in distributed transaction and need Automatic Transaction type
base.transactionType = MessageQueueTransactionType.Automatic;
return (OrderInfo)((Message)base.Receive()).Body;
} public OrderInfo Receive(int timeout)
{
base.timeout = TimeSpan.FromSeconds(Convert.ToDouble(timeout));
return Receive();
} public void Send(OrderInfo orderMessage)
{
// This method does not involve in distributed transaction and optimizes performance using Single type
base.transactionType = MessageQueueTransactionType.Single;
base.Send(orderMessage);
} --------------------编程问答--------------------
引用 1 楼 ly302 的回复:
代码是下面这个:

public new OrderInfo Receive()
{
// This method involves in distributed transaction and need Automatic Transaction type
base.transactionType = MessageQueueTransactionType.Automatic;
re……

此类回答不给分 --------------------编程问答-------------------- 希望有高手解答 --------------------编程问答-------------------- PetShop4是啥东西? --------------------编程问答-------------------- http://d.download.csdn.net/down/1352605/HDNGO --------------------编程问答--------------------
引用 5 楼 wiki14 的回复:
http://d.download.csdn.net/down/1352605/HDNGO

这些我都有,根本没讲MessageQueueTransactionType --------------------编程问答-------------------- 我只要MessageQueueTransactionType枚举项的详细解释,不要扯到PetShop上面去了 --------------------编程问答-------------------- 无满意回答不结贴
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,