C# 配置和使用多个队列
我在配置和使用多个队列时遇到麻烦 以下是我的startup类的内容:C# 配置和使用多个队列,c#,configuration,startup,hangfire,C#,Configuration,Startup,Hangfire,我在配置和使用多个队列时遇到麻烦 以下是我的startup类的内容: var options = new DashboardOptions { AppPath = VirtualPathUtility.ToAbsolute("~") }; app.UseHangfireDashboard("/jobs", options); var queues = new BackgroundJobServerOptio
var options = new DashboardOptions
{
AppPath = VirtualPathUtility.ToAbsolute("~")
};
app.UseHangfireDashboard("/jobs", options);
var queues = new BackgroundJobServerOptions
{
Queues = new[] { "high", "normal" }
};
app.UseHangfireServer(queues);
服务器正确启动,从仪表板上我可以看到队列
但当我尝试将进程排队时,hangfire总是将作业设置为默认队列。
这是对方法的调用:
BackgroundJob
.Enqueue<IFileConverterService>(
x => x.CreateSlides(docId, folderpath, priority));
我缺少什么?我已经解决了这个问题 在启动配置中,似乎必须定义一个默认队列,如图所示
var queues = new BackgroundJobServerOptions
{
Queues = new[] { "high", "default" }
};
然后实现一个带有Queue属性的方法和另一个没有Queue属性的方法
[Queue("high")]
public void CreateSlidesWithHighPriority(Guid documentId, string folderPath, int priority)
{
//my code
}
public void CreateSlidesWithLowPriority(Guid documentId, string folderPath, int priority)
{
//my code
}
现在一切都很好
[Queue("high")]
public void CreateSlidesWithHighPriority(Guid documentId, string folderPath, int priority)
{
//my code
}
public void CreateSlidesWithLowPriority(Guid documentId, string folderPath, int priority)
{
//my code
}