2015-11-24 86 views
1

結束我處理事件與HandleMyEvent類NServiceBus事件超時隊列

public class HandleMyEvent : IHandleMessages<MyEvent> 
{ 

    private readonly IBus _bus; 
    private readonly IWorkorker _workerTools; 


    public HandleProductInstanceEvent(IBus bus, IWorkorker worker) 
    { 
     _bus = bus; 
     _workerTools = worker; 

    } 

    public void Handle(IProductInstancesUpdatedEvent message) 
    { 
     var worker = new myWorker(_bus, _worker); 
     myWorker.DoWork(message.data); 
    } 
} 

myWorker.DoWork可以爲其做之前長達5分鐘。

當發佈者發送一個「MyEvent」時,看起來處理程序在消息在超時隊列中結束之前收到5個事件,我猜測它在放棄之前會重試5次。

在日誌文件中我能找到這個入口

NServiceBus.Unicast.Queuing.FailedToSendMessageException: Failed to send message to address: [email protected] ---> System.Messaging.MessageQueueException: Cannot enlist the transaction. 
    at System.Messaging.MessageQueue.SendInternal(Object obj, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType) 
    at NServiceBus.Transports.Msmq.MsmqMessageSender.Send(TransportMessage message, Address address) in c:\work\3206e2123f54fce4\src\NServiceBus.Core\Transports\Msmq\MsmqMessageSender.cs:line 59 

爲什麼會出現這個錯誤?

回答

3

您正在收到該錯誤,因爲默認情況下,處理NServiceBus中的MSMQ消息在超時時間爲1分鐘的事務中運行。

一旦你通過事務超時任何新的業務,如在數據庫中發送消息或儲存的東西,將與

失敗無法登記事務。

您應該將increase your transaction timeout設置爲大於預期的處理時間或此端點上的turn off transactions

請注意,運行5分鐘的消息處理程序是很長時間的。在很長一段時間內交易並因此鎖定交易資源並不是最佳選擇。

消息處理失敗後,事務回滾,將消息放回隊列。然後重試您配置的許多第一級重試嘗試。最有可能的5在你的情況。之後,它被轉移到二級重試。

.timeout隊列是負責處理二級重試的超時管理器的輸入隊列。如果消息沒有立即從此隊列中獲取,那麼您沒有在該端點上運行超時管理器。

+0

Added Configure.Transactions.Advanced( settings => settings.DefaultTimeout(TimeSpan.FromMinutes(10)));到我的端點配置,現在它工作:) – CruelIO