This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
47 lines (42 loc) · 1.48 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// **********************************************
// 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
// Example class to show how to run NServiceBus endpoints as Azure WebJobs
public class Program
{
static void Main()
{
try
{
var ec = new EndpointConfiguration("MyApp.NServiceBus.Backend");
new EndpointConfig().Customize(ec);
Task.Run(async () => await StartAsync(ec)).Wait();
}
catch (AggregateException e)
{
Console.Error.WriteLine(e);
}
}
private static async Task StartAsync(EndpointConfiguration ec)
{
IEndpointInstance endpoint = null;
endpoint = await Endpoint.Start(ec).ConfigureAwait(false);
#if DEBUG
Console.ReadLine();
#else
var cs = ConfigurationManager.ConnectionStrings["MyApp.NServiceBus.Backend.ConnectionString"].ConnectionString;
var builder = new HostBuilder();
var host = builder.Build();
using (host)
{
host.Run();
};
#endif
// shuts down NSB to properly release all acquired resources
await endpoint.Stop().ConfigureAwait(false);
}
}