限制 hangfire 从特定队列中获取作业

restricting hangfire to pick up jobs from a specific queue

我有 2 个 hangfire instances/servers 运行。两者都指向同一个 hangfire 数据库。如何限制其中一个 hangfire 实例仅从特定队列中获取作业并忽略其他队列?

谢谢

启动实例时,您可以提供要由服务器监视的队列列表:

app.UseHangfireServer(new BackgroundJobServerOptions()
    {
        // order defines priority
        // beware that queue names should be lowercase only
        Queues = new [] { "critical", "default", "myqueue" } 
    });

相信 Hangfire 服务器会轮询已注册队列的作业,所以如果您在多个服务器上注册了相同的队列,则先到先得。

如上所述,只需在每台服务器上设置一些具有唯一队列名称的队列,因为这是 Hangfire 用来确定处理位置的方法。

例如,在我的例子中,我有 1 个服务器用于一般维护队列,适用于所有服务器和一般应用程序,而环境服务器包含作业针对环境特定任务的队列。