Configuring Job Queues¶

Hangfire can process multiple queues. If you want to prioritize your jobs or split the processing across your servers (some processes the archive queue, others – the images queue, etc), you can tell Hangfire about your decisions.

To place a job into a different queue, use the QueueAttribute class on your method:

  1. [Queue("critical")]
  2. public void SomeMethod() { }
  3.  
  4. BackgroundJob.Enqueue(() => SomeMethod());

Queue name argument formatting

The Queue name argument must consist of lowercase letters, digits and underscore characters only.

To start to process multiple queues, you need to update your BackgroundJobServer configuration.

  1. var options = new BackgroundJobServerOptions
  2. {
  3. Queues = new[] { "critical", "default" }
  4. };
  5.  
  6. app.UseHangfireServer(options);
  7. // or
  8. using (new BackgroundJobServer(options)) { /* ... */ }

The order is important, workers will fetch jobs from the critical queue first, and then from the default queue.

原文:
原文:

http://docs.hangfire.io/en/latest/background-processing/configuring-queues.html