-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathProgram.cs
More file actions
57 lines (50 loc) · 2.58 KB
/
Program.cs
File metadata and controls
57 lines (50 loc) · 2.58 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
namespace Sample.Hybrid.ConsoleApp;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Sample.Hybrid.ConsoleApp.Application;
using Sample.Hybrid.ConsoleApp.EmailService;
using Sample.Hybrid.ConsoleApp.EmailService.Contract;
using SecretStore;
using SlimMessageBus.Host;
using SlimMessageBus.Host.AzureServiceBus;
using SlimMessageBus.Host.Memory;
using SlimMessageBus.Host.Serialization.Json;
class Program
{
public static Task Main(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((ctx, services) =>
{
services.AddHostedService<MainApplication>();
Secrets.Load(@"..\..\..\..\..\secrets.txt");
services
.AddSlimMessageBus((mbb) =>
{
// In summary:
// - The CustomerChangedEvent messages will be going through the SMB Memory provider.
// - The SendEmailCommand messages will be going through the SMB Azure Service Bus provider.
// - Each of the bus providers will serialize messages using JSON and use the same DI to resolve consumers/handlers.
mbb
// Bus 1
.AddChildBus("Memory", (mbbChild) =>
{
mbbChild
.WithProviderMemory()
.AutoDeclareFromAssemblyContaining<CustomerChangedEventHandler>(consumerTypeFilter: consumerType => consumerType.Namespace.Contains("Application"));
})
// Bus 2
.AddChildBus("AzureSB", (mbbChild) =>
{
var serviceBusConnectionString = Secrets.Service.PopulateSecrets(ctx.Configuration["Azure:ServiceBus"]);
mbbChild
.WithProviderServiceBus(cfg => cfg.ConnectionString = serviceBusConnectionString)
.Produce<SendEmailCommand>(x => x.DefaultQueue("test-ping-queue"))
.Consume<SendEmailCommand>(x => x.Queue("test-ping-queue").WithConsumer<SmtpEmailService>());
})
.AddServicesFromAssemblyContaining<CustomerChangedEventHandler>()
.AddJsonSerializer(); // serialization setup will be shared between bus 1 and 2
});
})
.Build()
.RunAsync();
}