Is hangfire suitable to run "infinite loop" job?

I’d like to listen to a message bus inside my WEB API 2 application. The context is that I have multiple web api applications and they need to interact with each other.

At the moment, I instanciate the message bus client inside a method called by WebActivator:PreApplicationStartMethod.

The problem is that if multiple workers start on IIS, I have multiple instances of the message bus client which is not what I want (ex: the sync will be launched multiple times) !

The second problem is that if there is no request on the web api for a while, IIS stops the application and so no one listen to the message bus …

Is hangfire suited for this requirement ? From what I understand, hangfire is not suited for this kind of “job” since the “job” never finishes

Is a windows service with the message bus client a better alternative ?

You can implement your job as a IBackgroundProcess, which HangFire will keep executing infinitely - you can add an interval by calling WaitOne on the CancallationToken passed as a parameter to the Execute method.

An example is here https://github.com/HangfireIO/Hangfire/blob/master/src/Hangfire.SqlServer/ExpirationManager.cs#L98