How to create non-duplicating recurring job in Hangfire where application is hosted in 2 instances

Hi All,

I’m new to Hangfire and I have created a Blank ASP.net core project (Hangfire + SQL) and setup a recurring job that is supposed to run every hour. The job will just send a message to Rabbit MQ and Rabbit MQ will process it from there. I am trying to handle a situation where the same application is deployed in multiple server instances but the recurring job should not be triggered multiple times. The idea is that if the first server instance is down then the jobs should be executed by the second instance. But if both servers are up, the recurring jobs should not get executed twice as there is no way for Rabbit MQ to understand a duplicate message.

Please let me know if anyone has any idea regarding this. Thank You!

1 Like

Hey @PC_Dev, how are you doing?

Did you get some solution for your problem with hangfire? I am facing the same issue! :slightly_frowning_face:

Here we have a scaling process to handle resources usage and sometimes our recurring jobs are been executed in all instances!

For your case using the RabbitMQ you can try using this plugin: https://github.com/noxdafox/rabbitmq-message-deduplication

Hi @j.martins I’m doing well. Hope you’re fine as well. I am posting a github link for your reference. This was the final change I made to make this work in production without having duplicated recurring jobs.

If the sql server configuration is handled properly, hangfire takes care of not repeating the same job. In my case I have a recurring job that should run every 1 hour.

Hope this helps!

Thanks
PC