Multiple Servers and MSMQ

Tags: #<Tag:0x00007f066c693948>

I’m trying to set up an environment where we have two servers running Hangfire jobs on MSMQ. Here is a summary:

Server A: One Hangfire queue (serveraqueue), no publicly accessible website
Server B: Two Hangfire queues (serverbqueue, serverbqueue2), website hosting a web app that enqueues jobs

Users visit website hosted on Server B, queue jobs that are executed on hangfire. Depending on the type of job, it will be executed either on ServerA or ServerB. Both servers are connected to the same SQL server database for storing Hangfire jobs (with SqlServerStorage object). They each have their own MSMQ private queues set up according to the documentation.

This works fine with SQL Server used as the queuing mechanism. Because of the invisibility timeout and polling interval, I’d prefer to use MSMQ if possible. But, when configured with MSMQ, the jobs that are supposed to be executed on Server A don’t get executed. They remain in the queue.

I created a skeleton MVC app to illustrate the issue. The key parts are:
HangfireBootstrapper.cs (where the BackgroundJobServer objects are set up)
BackgroundJobs.cs (where the jobs are executed)
Default1Controller.cs (where jobs are enqueued)

On ServerA, in Web.config, I set ServerRole to “ServerA” so that only the serveraqueue is set up for the BackgroundJobServer.
On ServerB, in Web.config, I set ServerRole to “ServerB” so that only serverbqueue, and serverbqueue2 are set up for the BackgroundJobServer.

Any help on this is greatly appreciated!

I had the exact same problem as this. Still unresolved to the point I just used SQL server. Not ideal. Be interested in hearing any solution you find :slight_smile: