3
此documentation表示您可以通過在要調用的方法上使用Queue
屬性來指定隊列。這假定你總是希望在同一個隊列上執行一個方法。是否有一種方法讓調用Enqueue
的過程指定將作業放入隊列的名稱(有效地將決策權交給作業生成器,而不是作業的定義)。在HangFire中,我可以使用隊列名稱而不是使用隊列屬性來排隊嗎?
此documentation表示您可以通過在要調用的方法上使用Queue
屬性來指定隊列。這假定你總是希望在同一個隊列上執行一個方法。是否有一種方法讓調用Enqueue
的過程指定將作業放入隊列的名稱(有效地將決策權交給作業生成器,而不是作業的定義)。在HangFire中,我可以使用隊列名稱而不是使用隊列屬性來排隊嗎?
通過IBackgroundJobClient實例,您可以指定一個隊列。
IBackgroundJobClient hangFireClient = new BackgroundJobClient();
EnqueuedState myQueueState = new Hangfire.States.EnqueuedState("myQueue");
hangFireClient.Create<SomeClass>(c => c.SomeMethod(), myQueueState);
請注意,通過這種方式,重試會將作業恢復到默認隊列。你將需要額外的代碼在同一個隊列重試,使用JobFilter
http://discuss.hangfire.io/t/one-queue-for-the-whole-farm-and-one-queue-by-server/490/3
我已經試過了,但它給了我,儘管使用...創建「無法創建inteface的實例」( x => x.Bar(),myQueueState)。有任何想法嗎? –
JohanLarsson
可能缺少依賴注入解析器,但我現在猜測你已經解決了你的問題。對不起,沒有早點看到你的問題。 – Xavero
爲我工作。類和方法不能是靜態的,但它工作正常。 –