Running multiple instances of hangfire using same SQL database

As per the documentation here http://docs.hangfire.io/en/latest/background-processing/running-multiple-server-instances.html

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.

I have configured hangfire to use MS-SQL. When i executed for the first time, as expected, it generates required SQL tables. and also creates an entry in [Server].[Id] column as desktop-31l17pk:ff24f03f-4edf-4833-b544-fd3d89b3a087

However [Server].[Id] column has no foreign key relationship with any other table.

So now lets say i have multiple instances of Hangfire running and all the instances are using same SQL database. ( I would expect hangfire will create unique [Server].[Id] for each instance). But since there is no foreign key relationship with other tables how hangfire would pickup job for a particular instance?

Hangfire doesn’t pick up jobs for instances, it picks up jobs for queues. Any server instance that handles the queue the job was enqueued to can pick up that job.

Can anyone please guide me to how queue works. When i configure hangfire with queue it never picks up the the job. I am using .Net Core.

This how i am configuring hangfire on startup. each instance has its own queue name

 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
 {
        app.UseHangfireServer(new BackgroundJobServerOptions()
        {
            Queues = new string[] { "Instance1" }
        });
   }

This is how i Enqueue job

_backGroundJobClient.Enqueue<IPrepareService>(x => x.Start(request.ID));

i found how to use queue here however based on the comments there, even with queue, so many are having issues configuring multiple instances.

So based on the documentation i have configured as below

 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
 {
        app.UseHangfireServer(new BackgroundJobServerOptions()
        {
            Queues = new string[] { "instance1" }
        });
   }

Method to invoke

[Queue("instance1")]
public async Task Start(int requestID)
{
    
}

This is how i Enqueue job
_backGroundJobClient.Enqueue<IPrepareService>(x => x.Start(request.ID));

however when i check [JobQueue] table the new job has queue name default and becuase of that hangfire will never pickup that job
I think this is a bug

Found one more thing. I am using instance of IBackgroundJobClient. The instance is automatically get injected by .Net Core’s inbuilt container.

So if i use instance to enqueue the job then hangfire creates new job with default queue name

     _backGroundJobClient.Enqueue<IPrepareService>(x => x.Start(request.ID));

However if i use static method, then hangfire creates new job with configured queue name instance1

    BackgroundJob.Enqueue<IPrepareService>(x => x.Start(prepareRequest.ID));

How do i configure hangfire in .Net Core so the instance of IBackgroundJobClient will use configure queue name ?

That is a bug in Hangfire.AspNetCore. Refer to this issue for the temporary solution: https://github.com/HangfireIO/Hangfire/issues/799