我正在尝试从MSMQ专用队列读取数据,并尝试测试一个失败,这样我就可以确信,如果进程没有完成,那么详细信息将保留在队列中。目前,在我的事务范围内,它命中了我抛出的新异常行,并按预期落入捕获块,但看起来好像是事务。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);
}