MSMQ 忽略事务范围
MSMQ ignoring transaction scope
我正在尝试从 MSMQ 私有队列中读取数据,并且正在尝试测试失败,以便我可以确信如果进程没有完成,那么详细信息将保留在队列中。目前在我的事务范围内,它命中了我的 throw new Exception 行并按预期落入 catch 块,但看起来 transaction.Complete 得到了 运行,因为在抛出异常之后,队列为空:这是我的代码片段 -
try
{
using (TransactionScope transaction = new TransactionScope())
{
Message incoming = new Message
{
Formatter = formatter,
AcknowledgeType = AcknowledgeTypes.FullReceive,
Recoverable = true
};
incoming = msgQ.Receive(new TimeSpan(0, 0, 3), MessageQueueTransactionType.Single);
if (incoming != null)
{
MemoryStream mem = (MemoryStream) incoming.BodyStream;
mem.Seek(0, SeekOrigin.Begin);
IFormatter ifm = new BinaryFormatter();
var deserialisedMessage = (TravelMessageServiceObjects) ifm.Deserialize(mem);
ISubmissionsService submissionsService = new SubmissionsService();
bool retVal = submissionsService.PerformSubmission(deserialisedMessage.Products, deserialisedMessage.PolicyReference);
if (!retVal)
{
string errorMessage = string.Concat("Policy Ref: ", deserialisedMessage.PolicyReference,
" Product: ", Enum.GetName(typeof(Products), deserialisedMessage.Products));
throw new Exception(errorMessage);
}
}
transaction.Complete();
}
}
catch (Exception ex)
{
IError logger = new Logger();
logger.Log(this, SeverityEnum.Warning, ex);
}
将您的队列创建为事务性队列
并将MessageQueueTransactionType
设置为Automatic
。 Single
仅适用于内部消息队列事务。
incoming = msgQ.Receive(new TimeSpan(0, 0, 3), MessageQueueTransactionType.Automatic);
检查,MSDTC 正常。
检查,防火墙没有阻止通信
我正在尝试从 MSMQ 私有队列中读取数据,并且正在尝试测试失败,以便我可以确信如果进程没有完成,那么详细信息将保留在队列中。目前在我的事务范围内,它命中了我的 throw new Exception 行并按预期落入 catch 块,但看起来 transaction.Complete 得到了 运行,因为在抛出异常之后,队列为空:这是我的代码片段 -
try
{
using (TransactionScope transaction = new TransactionScope())
{
Message incoming = new Message
{
Formatter = formatter,
AcknowledgeType = AcknowledgeTypes.FullReceive,
Recoverable = true
};
incoming = msgQ.Receive(new TimeSpan(0, 0, 3), MessageQueueTransactionType.Single);
if (incoming != null)
{
MemoryStream mem = (MemoryStream) incoming.BodyStream;
mem.Seek(0, SeekOrigin.Begin);
IFormatter ifm = new BinaryFormatter();
var deserialisedMessage = (TravelMessageServiceObjects) ifm.Deserialize(mem);
ISubmissionsService submissionsService = new SubmissionsService();
bool retVal = submissionsService.PerformSubmission(deserialisedMessage.Products, deserialisedMessage.PolicyReference);
if (!retVal)
{
string errorMessage = string.Concat("Policy Ref: ", deserialisedMessage.PolicyReference,
" Product: ", Enum.GetName(typeof(Products), deserialisedMessage.Products));
throw new Exception(errorMessage);
}
}
transaction.Complete();
}
}
catch (Exception ex)
{
IError logger = new Logger();
logger.Log(this, SeverityEnum.Warning, ex);
}
将您的队列创建为事务性队列
并将MessageQueueTransactionType
设置为Automatic
。 Single
仅适用于内部消息队列事务。
incoming = msgQ.Receive(new TimeSpan(0, 0, 3), MessageQueueTransactionType.Automatic);
检查,MSDTC 正常。
检查,防火墙没有阻止通信