In this skills lab I am exploring remote Hangfire job execution using a common pub/sub pattern with Azure Service Bus.
In order to clone and run this project you must obtain the following:
-
Hangfire Ace licence with access to the private NuGet feed for throttling
-
Access to a SQL Server instance with two databases on it using Windows authentication,
hf_server_a
andhf_server_b
-
Azure subscription with a Service Bus resource:
- Make sure you copy the connection string to add the
appsettings
later - Setup the following Queues in the Service Bus Namespace:
servera
andserverb
- Make sure you copy the connection string to add the
-
Roll through each of the
ServerX
andClientX
projects and create anappsettings.Development.json
file- For the
ClientX
project settings, specify the following:
{ "ConnectionStrings": { "HangfireConnection": "Server={YOUR SQL SERVER};Database={hf_server_a|hf_server_b};Trusted_Connection=True;", "ServiceBusConnection": "{YOUR SERVICE BUS CONNECTION STRING}" } }
- For the
ServerX
project settings, specify the following:
{ "ConnectionStrings": { "HangfireConnection": "Server={YOUR SQL SERVER};Database={hf_server_a|hf_server_b};Trusted_Connection=True;", "ServiceBusConnection": "{YOUR SERVICE BUS CONNECTION STRING}" }, "ServiceBusListeningQueueName": "{servera|serverb}" }
- For the
-
Configure the startup projects for the solution to start both
ServerX
and bothClientX
applications -
Run the solution
-
On startup, you should get two browser windows displaying the Swagger UI for each
ClientX
, split the windows side-by-side -
Duplicate the Swagger UI tabs and change the URL to
/hangfire
, the Hangfire dashboard will appear -
Against Server A Swagger UI, expand the
enqueue
endpoint and using the Try It Out feature, make a request
-
Switch to the Hangfire Dashboard tabs and observe the realtime graph report one job execution (on both sides)
-
In both dashboards, go to Jobs > Succeeded:
- On
ServerA
(source), you will see a successful job and console logs forIRunRemoteWorkflow.Run
- On
ServerB
(subscribed listener), you will see a successful job and console logs forIRunWorkflow.Run
which has received the message and performed the job, using message parameters
- On