forked from zarusz/SlimMessageBus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
95 lines (78 loc) · 2.73 KB
/
Program.cs
File metadata and controls
95 lines (78 loc) · 2.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System.Reflection;
using Sample.AsyncApi.Service.Messages;
using Saunter;
using Saunter.AsyncApiSchema.v2;
using SecretStore;
using SlimMessageBus.Host;
using SlimMessageBus.Host.AsyncApi;
using SlimMessageBus.Host.AzureServiceBus;
using SlimMessageBus.Host.Memory;
using SlimMessageBus.Host.Serialization.Json;
// Local file with secrets
Secrets.Load(@"..\..\secrets.txt");
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
//builder.Services.AddEndpointsApiExplorer();
//builder.Services.AddSwaggerGen();
builder.Services.AddSwaggerDocument();
var configuration = builder.Configuration;
builder.Services.AddSlimMessageBus(mbb =>
{
mbb
.AddChildBus("Memory", mbb =>
{
mbb
.WithProviderMemory()
.AutoDeclareFrom(Assembly.GetExecutingAssembly(), consumerTypeFilter: t => t.Name.Contains("Command"));
})
.AddChildBus("AzureSB", mbb =>
{
mbb
.WithProviderServiceBus(cfg => cfg.ConnectionString = Secrets.Service.PopulateSecrets(configuration["Azure:ServiceBus"]))
.Produce<CustomerEvent>(x =>
{
x.DefaultTopic("samples.asyncapi/customer-events");
})
.Consume<CustomerEvent>(x =>
{
x.Topic("samples.asyncapi/customer-events");
x.SubscriptionName("asyncapi-service");
x.WithConsumer<CustomerCreatedEventConsumer, CustomerCreatedEvent>();
});
})
.AddServicesFromAssembly(Assembly.GetExecutingAssembly())
.AddJsonSerializer()
.AddAsyncApiDocumentGenerator();
});
// doc:fragment:ExampleStartup2
// Add Saunter to the application services.
builder.Services.AddAsyncApiSchemaGeneration(options =>
{
options.AsyncApi = new AsyncApiDocument
{
Info = new Info("SlimMessageBus AsyncAPI Sample API", "1.0.0")
{
Description = "This is a sample of the SlimMessageBus AsyncAPI plugin",
License = new License("Apache 2.0")
{
Url = "https://www.apache.org/licenses/LICENSE-2.0"
}
}
};
});
// doc:fragment:ExampleStartup2
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseOpenApi();
app.UseSwaggerUi();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
// Register AsyncAPI docs via Sauter
app.MapAsyncApiDocuments();
app.MapAsyncApiUi();
app.Run();