ServiceBus Queue support for SQL Server job storage implementation
Switch branches/tags
Nothing to show
Clone or download
danjus10 and barclayadam Updated Read Me for Options
Added reference to LoopReceiveTimeout to lift onto initial setup
Latest commit 8ad1e47 Dec 13, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
.nuget Update NuGet client executable to 3.5 RTM Aug 25, 2017
src Bump to v3.0.1 Nov 7, 2018
tests/HangFire.Azure.ServiceBusQueue.Tests Consolidate NuGet + fix build.bat build Mar 28, 2017
.gitignore Initial commit May 17, 2014
HangFire.Azure.ServiceBusQueue.sln KeepAlive jobs to avoid lock lost + test project Mar 28, 2017
appveyor.yml Bump to v3.0.1 Nov 7, 2018
build.bat Change project structure, add build scripts Aug 13, 2015
license.txt Initial commit May 17, 2014
psake-project.ps1 Change project structure, add build scripts Aug 13, 2015 Updated Read Me for Options Dec 13, 2018


Official Site Latest version Build status License MIT

What is it?

Adds support for using Azure Service Bus Queues with Hangfire's SQL storage provider to reduce latency and remove the need to poll the database for new jobs.

All job data continues to be stored and maintained within SQL storage, but polling is removed in favour of pushing the job ids through the service bus.


Hangfire.Azure.ServiceBusQueue is available as a NuGet package. Install it using the NuGet Package Console window:

PM> Install-Package Hangfire.Azure.ServiceBusQueue


To use the queue it needs to be added to your existing SQL Server storage configuration, using one of the UseServiceBusQueues overloads:

var sqlStorage = new SqlServerStorage("<connection string>");

// The connection string *must* be for the root namespace and have the "Manage"
// permission if used by the dashboard
var connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");

// You can configure queues on first creation using this action
Action<QueueDescription> configureAction = qd =>
    qd.MaxSizeInMegabytes = 5120;
    qd.DefaultMessageTimeToLive = new TimeSpan(0, 1, 0);

// Uses default options (no prefix or configuration) with the "default" queue only

// Uses default options (no prefix or configuration) with the "critical" and "default" queues
sqlStorage.UseServiceBusQueues(connectionString, "critical", "default"); 

// Configures queues on creation and uses the "crtical" and "default" queues
sqlStorage.UseServiceBusQueues(connectionString, configureAction, "critical", "default"); 
// Specifies all options
sqlStorage.UseServiceBusQueues(new ServiceBusQueueOptions
        ConnectionString = connectionString,
        Configure = configureAction,
        // The actual queues used in Azure will have this prefix if specified
        // (e.g. the "default" queue will be created as "my-prefix-default")
        // This can be useful in development environments particularly where the machine
        // name could be used to separate individual developers machines automatically
        // (i.e. "my-prefix-{machine-name}".Replace("{machine-name}", Environment.MachineName))
        QueuePrefix = "my-prefix-",
        // The queues to monitor. This *must* be specified, even to set just
        // the default queue as done here
        Queues = new [] { EnqueuedState.DefaultQueue },
        // By default queues will be checked and created on startup. This option
        // can be disabled if the application will only be sending / listening to 
        // the queue and you want to remove the 'Manage' permission from the shared
        // access policy.
        // Note that the dashboard *must* have the 'Manage' permission otherwise the
        // queue length cannot be read
        CheckAndCreateQueues = false,
        // Typically a lower value is desired to keep the throughput of message processing high. A lower timeout means more calls to
        // Azure Service Bus which can increase costs, especially on an under-utilised server with few jobs.
        // Use a Higher value for lower costs in non production or non critical jobs
        LoopReceiveTimeout = TimeSpan.FromMilliseconds(500)


Questions? Problems?

Open-source project are developing more smoothly, when all discussions are held in public.

If you have any questions or problems related to Hangfire itself or this queue implementation or want to discuss new features, please visit the discussion forum. You can sign in there using your existing Google or GitHub account, so it's very simple to start using it.

If you've discovered a bug, please report it to the Hangfire GitHub Issues. Detailed reports with stack traces, actual and expected behavours are welcome.


Hangfire.Azure.ServiceBusQueues is released under the MIT License.