Hangfire.Azure.ServiceBusQueue 6.0.0

Prefix Reserved
dotnet add package Hangfire.Azure.ServiceBusQueue --version 6.0.0
                    
NuGet\Install-Package Hangfire.Azure.ServiceBusQueue -Version 6.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hangfire.Azure.ServiceBusQueue" Version="6.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hangfire.Azure.ServiceBusQueue" Version="6.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Hangfire.Azure.ServiceBusQueue" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Hangfire.Azure.ServiceBusQueue --version 6.0.0
                    
#r "nuget: Hangfire.Azure.ServiceBusQueue, 6.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Hangfire.Azure.ServiceBusQueue&version=6.0.0
                    
Install Hangfire.Azure.ServiceBusQueue as a Cake Addin
#tool nuget:?package=Hangfire.Azure.ServiceBusQueue&version=6.0.0
                    
Install Hangfire.Azure.ServiceBusQueue as a Cake Tool

Hangfire.Azure.ServiceBusQueue

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.

Installation

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

PM> Install-Package Hangfire.Azure.ServiceBusQueue

Compatibility

Hangfire v1.7+ introduced breaking changes to the SQL Server integration points and requires at least version 4.0.0 of this library. If you are on an older version of Hangfire please use a lower version of Hangfire.Azure.ServiceBusQueue

Usage

To use the queue it needs to be added to your existing SQL Server storage configuration.

For .NETCore and beyond, you can use the IGlobalConfiguration extension .UseServiceBusQueues:


//You can use .UseServiceBusQueues only after .UseSqlStorage()

// Uses default options (no prefix or configuration) with the "default" queue only
services.AddHangfire(configuration => configuration
    .UseSqlServerStorage("<sql connection string>")
    .UseServiceBusQueues("<azure servicebus connection string>")
    
// Uses default options (no prefix or configuration) with the "critical" and "default" queues
services.AddHangfire(configuration => configuration
    .UseSqlServerStorage("<sql connection string>")
    .UseServiceBusQueues("<azure servicebus connection string>", "critical", "default")
    
// Configures queues on creation and uses the "crtical" and "default" queues
services.AddHangfire(configuration => configuration
    .UseSqlServerStorage("<sql connection string>")
    .UseServiceBusQueues("<azure servicebus connection string>", 
        queueOptions => {
            queueOptions.MaxSizeInMegabytes = 5120;
            queueOptions.DefaultMessageTimeToLive = new TimeSpan(0, 1, 0);
        } "critical", "default")
    
// Specifies all options
services.AddHangfire(configuration => configuration
    .UseSqlServerStorage("<sql connection string>")
    .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)
        
        // Delay between queue polling requests
        QueuePollInterval = TimeSpan.Zero
    }));

You can also use 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
sqlStorage.UseServiceBusQueues(connectionString);

// 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,

        Credential = new DefaultAzureCredential() // any Azure.Identity.TokenCredential
                
        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)
        
        // Delay between queue polling requests
        QueuePollInterval = TimeSpan.Zero
    });

GlobalConfiguration.Configuration
    .UseStorage(sqlStorage);

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.

License

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

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.0.0 227 4/14/2025
5.0.0 73,471 10/5/2021
4.1.0 182,071 5/11/2019
4.0.0 1,305 4/9/2019
3.0.1 7,973 11/7/2018
3.0.0 4,632 10/29/2018
2.2.2 2,467 5/1/2019
2.2.1 30,450 8/25/2017
2.2.0 23,449 3/28/2017
2.1.1 38,642 3/18/2016
2.1.0 1,616 3/18/2016
2.0.0 2,447 11/5/2015
1.0.0 1,876 9/22/2015
0.0.1 2,070 5/17/2014