forked from dotnet/orleans
/
EventHubStreamBuilder.cs
79 lines (72 loc) · 3.72 KB
/
EventHubStreamBuilder.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
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
using Microsoft.Extensions.DependencyInjection;
using Orleans.Configuration;
using Orleans.Hosting;
using Orleans.ServiceBus.Providers;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Orleans.Providers.Streams.Common;
using Orleans.ApplicationParts;
namespace Orleans.Streams
{
public class SiloEventHubStreamConfigurator : SiloRecoverableStreamConfigurator
{
public SiloEventHubStreamConfigurator(string name,
Action<Action<IServiceCollection>> configureServicesDelegate, Action<Action<IApplicationPartManager>> configureAppPartsDelegate)
: base(name, configureServicesDelegate, EventHubAdapterFactory.Create)
{
configureAppPartsDelegate(parts =>
{
parts.AddFrameworkPart(typeof(EventHubAdapterFactory).Assembly)
.AddFrameworkPart(typeof(EventSequenceTokenV2).Assembly);
});
this.configureDelegate(services => services.ConfigureNamedOptionForLogging<EventHubOptions>(name)
.ConfigureNamedOptionForLogging<EventHubReceiverOptions>(name)
.ConfigureNamedOptionForLogging<EventHubStreamCachePressureOptions>(name)
.AddTransient<IConfigurationValidator>(sp => new EventHubOptionsValidator(sp.GetOptionsByName<EventHubOptions>(name), name))
.AddTransient<IConfigurationValidator>(sp => new StreamCheckpointerConfigurationValidator(sp, name)));
}
public SiloEventHubStreamConfigurator ConfigureCheckpointer<TOptions>(Func<IServiceProvider, string, IStreamQueueCheckpointerFactory> checkpointerFactoryBuilder, Action<OptionsBuilder<TOptions>> configureOptions)
where TOptions : class, new()
{
this.ConfigureComponent<TOptions, IStreamQueueCheckpointerFactory>(checkpointerFactoryBuilder, configureOptions);
return this;
}
public SiloEventHubStreamConfigurator ConfigureEventHub(Action<OptionsBuilder<EventHubOptions>> configureOptions)
{
this.Configure<EventHubOptions>(configureOptions);
return this;
}
public SiloEventHubStreamConfigurator ConfigurePartitionReceiver(Action<OptionsBuilder<EventHubReceiverOptions>> configureOptions)
{
this.Configure<EventHubReceiverOptions>(configureOptions);
return this;
}
public SiloEventHubStreamConfigurator ConfigureCachePressuring(Action<OptionsBuilder<EventHubStreamCachePressureOptions>> configureOptions)
{
this.Configure<EventHubStreamCachePressureOptions>(configureOptions);
return this;
}
}
public class ClusterClientEventHubStreamConfigurator : ClusterClientPersistentStreamConfigurator
{
public ClusterClientEventHubStreamConfigurator(string name, IClientBuilder builder)
: base(name, builder, EventHubAdapterFactory.Create)
{
this.clientBuilder.ConfigureApplicationParts(parts =>
{
parts.AddFrameworkPart(typeof(EventHubAdapterFactory).Assembly)
.AddFrameworkPart(typeof(EventSequenceTokenV2).Assembly);
})
.ConfigureServices(services => services.ConfigureNamedOptionForLogging<EventHubOptions>(name)
.AddTransient<IConfigurationValidator>(sp => new EventHubOptionsValidator(sp.GetOptionsByName<EventHubOptions>(name), name)));
}
public ClusterClientEventHubStreamConfigurator ConfigureEventHub(Action<OptionsBuilder<EventHubOptions>> configureOptions)
{
this.Configure<EventHubOptions>(configureOptions);
return this;
}
}
}