Skip to content

Instantly share code, notes, and snippets.

@hd9

hd9/NServiceBus-WebJob.cs

Last active Feb 7, 2020
Embed
What would you like to do?
Sample initialization code for NServiceBus running on Azure WebJobs
// **********************************************
// Fore more information, visit:
// https://blog.hildenco.com/2020/02/migrating-nservicebus-backends-to-azure.html
// **********************************************
// Related docs:
// * NSB WebJobs: https://docs.particular.net/samples/azure/webjob-host/
// * Azure WebJobs: https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-get-started
public class Program
{
static void Main()
{
try
{
var epc = new EndpointConfiguration("MyApp.NServiceBus.Backend");
new EndpointConfig().Customize(epc);
var endpoint = Endpoint.Start(epc).GetAwaiter().GetResult();
var builder = new HostBuilder();
var host = builder.Build();
using (host)
{
host.Run();
}
// shuts down NSB to properly release all acquired resources
endpoint.Stop().GetAwaiter().GetResult();
}
catch (Exception e)
{
Console.Error.WriteLine(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment