我有一个端点,可以作为其他三个工作端点的分发服务器。 收到的消息的处理端点打开一个事务,并尝试将一些xml数据导入到sql db中。如果在此过程中抛出某个异常,则会捕获异常,回滚事务并将xml数据写入错误文件夹。 简化,它看起来像:
public void Handle(doSomethingCmd message)
{
System.Data.SqlClient.BeginTransaction();
try
{
//... some xml data import
throw new Exception();
//Commit if succeded
}
catch (Exception exception)
{
System.Data.IDbTransaction.Rollback();
//...Write file to error folder
}
}
首先,事务回滚后不会重试。但是当再次发送消息时,所有工作端点(仅工作者)都会获得异常(无法登记事务,无法将msg发送到控制队列 - >请参阅下面的stacktrace)并且nservicebus会重试该消息(这会导致这种情况,该文件在错误文件夹中多次出现) 看起来分布式事务处于无效状态。我可以移交异常(重新抛出异常),所以nservicebus为我处理回滚,但在这种情况下,文件也被写入错误文件夹几次(由于重试机制)
Failed raising finished message processing event.|NServiceBus.Unicast.Queuing.FailedToSendMessageException: Failed to send message to address: someEndpoint.distributor.control@SRVPS01 ---> System.Messaging.MessageQueueException: Cannot enlist the transaction.
at System.Messaging.MessageQueue.SendInternal(Object obj, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType)
at System.Messaging.MessageQueue.Send(Object obj, MessageQueueTransactionType transactionType)
at NServiceBus.Transports.Msmq.MsmqMessageSender.Send(TransportMessage message, Address address) in c:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\Transports\Msmq\MsmqMessageSender.cs:line 49
--- End of inner exception stack trace ---
at NServiceBus.Transports.Msmq.MsmqMessageSender.ThrowFailedToSendException(Address address, Exception ex) in c:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\Transports\Msmq\MsmqMessageSender.cs:line 88
at NServiceBus.Transports.Msmq.MsmqMessageSender.Send(TransportMessage message, Address address) in c:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\Transports\Msmq\MsmqMessageSender.cs:line 75
at NServiceBus.Distributor.MSMQ.ReadyMessages.ReadyMessageSender.SendReadyMessage(String sessionId, Int32 capacityAvailable, Boolean isStarting) in c:\BuildAgent\work\c3100604bbd3ca20\src\NServiceBus.Distributor.MSMQ\ReadyMessages\ReadyMessageSender.cs:line 62
at NServiceBus.Distributor.MSMQ.ReadyMessages.ReadyMessageSender.TransportOnFinishedMessageProcessing(Object sender, FinishedMessageProcessingEventArgs e) in c:\BuildAgent\work\c3100604bbd3ca20\src\NServiceBus.Distributor.MSMQ\ReadyMessages\ReadyMessageSender.cs:line 50
at System.EventHandler1.Invoke(Object sender, TEventArgs e)
at NServiceBus.Unicast.Transport.TransportReceiver.OnFinishedMessageProcessing(TransportMessage msg) in c:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\Unicast\Transport\TransportReceiver.cs:line 435
答案 0 :(得分:2)
工人通过向经销商发送消息来结束工作单元。此发送将加入现有的分布式事务。您获得的错误是由尝试加入已经失败的事务的新事务资源引起的。有些事情已将分布式事务标记为回滚。
这通常是由您的代码引起的。您的数据库操作以某种方式失败,或者您可能已超过处理该消息的事务超时限制。 (默认一分钟)
检查日志以查看您是否在事务超时限制之上使用以处理工作人员上的消息。