1

我在配置和使用多个队列时遇到了麻烦。

以下是我的创业课内容:

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));

这是方法实现:

public class FileConverterService : IFileConverterService
{
    [Queue("high")]
   public void CreateSlides(Guid documentId, string folderPath, int priority)
   {
       //my stuff
   }
}

我错过了什么?

4

1 回答 1

2

我已经解决了这个问题。

在启动配置中,似乎必须定义一个默认队列,如图所示

 var queues = new BackgroundJobServerOptions
            {
                Queues = new[] { "high", "default" }
            };

然后实现一个具有 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
    }

现在一切正常。

于 2015-09-11T08:54:42.540 回答