我有以下情況:NServiceBus - 如何爲每個消息類型接收器訂閱的單獨隊列?
因此,接收器訂閱兩種事件:eventA和eventB。 NServiceBus爲接收方(Receiver)創建隊列,並將類型爲eventA和eventB的消息放置到同一隊列中。問題是,如果我可以配置NServiceBus爲接收方的每種類型的事件使用單獨的隊列(ReceiverEventA和ReceiverEventB)?或者我可以在單個進程中有兩個接收器(並且每個接收器都有獨立的隊列)。 問題是,EventA比EventB處理時間要長得多,而且它們是獨立的 - 所以如果它們處於單獨的隊列中,它們可以同時處理。
更新:如果我有這樣幼稚的做法去,接收器無法啓動與空引用異常:
private static IBus GetBus<THandler, TEvent>()
{
var bus = Configure.With(new List<Type>
{
typeof(THandler),
typeof(TEvent),
typeof(CompletionMessage)
})
.Log4Net()
.DefaultBuilder()
.XmlSerializer()
.MsmqTransport()
.IsTransactional(true)
.PurgeOnStartup(false)
.UnicastBus()
.LoadMessageHandlers()
.ImpersonateSender(false);
bus.Configurer.ConfigureProperty<MsmqTransport>(x => x.InputQueue, "Queue" + typeof(THandler).Name);
return bus.CreateBus().Start();
}
[STAThread]
static void Main()
{
Busses = new List<IBus>
{
GetBus<ItemEventHandlerA, ItemEventA>(),
GetBus<ItemEventHandlerB, ItemEventB>()
};
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new TestForm());
}
異常堆棧跟蹤是:
在NServiceBusTest2.WinFormsReceiver.Program在C:\ Users \ User \ Documents \ Visual Studio 2010 \ Projects \ NServiceBusTest2 \ NServiceBusTest2.WinFormsReceiver \ Program.cs中的.GetBusTHandler,TEvent中:NServiceBusTest2.WinFormsReceiver.Program.Main()中的第57行
。 User \ Documents \ Visual Studio 2 010 \項目\ NServiceBusTest2 \ NServiceBusTest2.WinFormsReceiver \的Program.cs:行26
在System.AppDomain._nExecuteAssembly(RuntimeAssembly組件,字串[] args)
在System.AppDomain.ExecuteAssembly(字符串assemblyFile,證據assemblySecurity,字符串[ ]參數) 在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在System.Threading.ThreadHelper.ThreadStart_Context(對象狀態)
在System.Threading.ExecutionContext.Run(的ExecutionContext的ExecutionContext,ContextCallback回調,對象的狀態, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state)
在System.Threading.ThreadHelper.ThreadStart()
我正在考慮將ThreadPool作爲工作項目拋出,但如果它失敗了呢?處理程序將完成它的工作,所以消息將從隊列中移除,並且沒有標準方法將其返回(或者我錯過了什麼?)。我們使用Windows窗體作爲流程管理工具 - 我在這裏提到了更具體的示例:https://github.com/NServiceBus/NServiceBus/issues/219 – Giedrius 2012-03-19 07:19:15
@Giedrius:提供了答案正文中的更新。 – 2012-03-19 15:04:26
感謝您的幫助。要回答你的問題 - WinForms是讓儀表板暫停/恢復,同時查看銷售渠道的當前狀態 - 這是處理的內容。我們發現有一種方法可以讓多個接收器使用不同的AppDomain,但總的來說,這是一種痛苦的解決方法。看起來我們必須接受AppDomain的解決方法,或者搜索NServiceBus的替代方案,或者重新考慮部署(現在我們有cc.net + clickOnce),並將儀表板和處理程序設置爲單獨的部分。 – Giedrius 2012-03-19 15:19:51