-
Notifications
You must be signed in to change notification settings - Fork 301
Expand file tree
/
Copy pathProgram.cs
More file actions
58 lines (44 loc) · 1.73 KB
/
Program.cs
File metadata and controls
58 lines (44 loc) · 1.73 KB
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
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using System.Text.Json;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using NServiceBus;
Console.Title = "Endpoint";
var builder = Host.CreateApplicationBuilder(args);
var endpointConfiguration = new EndpointConfiguration("Samples.ASBS.CloudEvents.Endpoint");
endpointConfiguration.EnableInstallers();
var connectionString = builder.Configuration.GetConnectionString("AzureServiceBusConnectionString");
if (string.IsNullOrWhiteSpace(connectionString))
{
throw new Exception("Could not read the 'AzureServiceBusConnectionString' value. Check the sample prerequisites.");
}
var transport = new AzureServiceBusTransport(connectionString, TopicTopology.Default);
endpointConfiguration.UseTransport(transport);
#region asb-cloudevents-serialization
endpointConfiguration.UseSerialization<SystemJsonSerializer>().Options(new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
IncludeFields = true
});
#endregion
#region asb-cloudevents-configuration
var cloudEventsConfiguration = endpointConfiguration.EnableCloudEvents();
#endregion
#region asb-cloudevents-typemapping
cloudEventsConfiguration.TypeMappings["Microsoft.Storage.BlobCreated"] = [typeof(BlobCreated)];
#endregion
Console.WriteLine("Press any key, the application is starting");
Console.TreatControlCAsInput = true;
var input = Console.ReadKey();
if (input.Key == ConsoleKey.C && (input.Modifiers & ConsoleModifiers.Control) != 0)
{
Environment.Exit(0);
}
Console.WriteLine("Starting...");
builder.UseNServiceBus(endpointConfiguration);
var host = builder.Build();
await host.StartAsync();
Console.WriteLine("Press any key to exit");
var key = Console.ReadKey();
await host.StopAsync();