Last active
February 7, 2020 19:26
-
-
Save hd9/e41c4b135466aa8fe9b7992ea36d32ea to your computer and use it in GitHub Desktop.
Sample initialization code for NServiceBus running on Azure WebJobs supporting local debug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ********************************************** | |
// 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 ec = new EndpointConfiguration("MyApp.NServiceBus.Backend"); | |
new EndpointConfig().Customize(ec); | |
var endpoint = Endpoint.Start(ec).GetAwaiter().GetResult(); | |
#if DEBUG | |
// nothing to do. In debug mode, run forever until the service is stopped. | |
while (true) Thread.Sleep(5000); | |
#else | |
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(); | |
#endif | |
} | |
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