Running multiple server instances¶

Obsolete since 1.5

You aren’t required to have additional configuration to support multiple background processing servers in the same process since Hangfire 1.5, just skip the article. Server identifiers are now generated using GUIDs, so all the instance names are unique.

It is possible to run multiple server instances inside a process, machine, or on several machines at the same time. Each server use distributed locks to perform the coordination logic.

Each Hangfire Server has a unique identifier that consist of two parts to provide default values for the cases written above. The last part is a process id to handle multiple servers on the same machine. The former part is the server name, that defaults to a machine name, to handle uniqueness for different machines. Examples: server1:9853, server1:4531, server2:6742.

Since the defaults values provide uniqueness only on a process level, you should handle it manually if you want to run different server instances inside the same process:

  1. var options = new BackgroundJobServerOptions
  2. {
  3. ServerName = String.Format(
  4. "{0}.{1}",
  5. Environment.MachineName,
  6. Guid.NewGuid().ToString())
  7. };
  8.  
  9. var server = new BackgroundJobServer(options);
  10.  
  11. // or
  12.  
  13. app.UseHangfireServer(options);

原文:
原文:

http://docs.hangfire.io/en/latest/background-processing/running-multiple-server-instances.html