Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<PackageReference Include="EstateManagement.Client" Version="1.1.6-build16" />
<PackageReference Include="EstateReporting.Database" Version="1.1.8-build15" />
<PackageReference Include="SecurityService.Client" Version="1.1.2-build20" />
<PackageReference Include="Shared" Version="1.5.1" />
<PackageReference Include="Shared.DomainDrivenDesign" Version="1.5.1" />
<PackageReference Include="Shared" Version="2022.12.0-beta4" />
<PackageReference Include="Shared.DomainDrivenDesign" Version="2022.12.0-beta4" />
<PackageReference Include="MediatR" Version="10.0.1" />
<PackageReference Include="Shared.EventStore" Version="1.5.1" />
<PackageReference Include="Shared.EventStore" Version="2022.12.0-beta4" />
<PackageReference Include="System.IO.Abstractions" Version="17.0.15" />
<PackageReference Include="TransactionProcessor.Client" Version="1.1.13-build22" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion FileProcessor.Client/FileProcessor.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ClientProxyBase" Version="1.5.1" />
<PackageReference Include="ClientProxyBase" Version="2022.12.0-beta4" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Shared.DomainDrivenDesign" Version="1.5.1" />
<PackageReference Include="Shared.DomainDrivenDesign" Version="2022.12.0-beta4" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Grpc.Net.Client" Version="2.47.0" />
<PackageReference Include="Shared.DomainDrivenDesign" Version="2022.12.0-beta4" />
<PackageReference Include="Shared.EventStore" Version="2022.12.0-beta4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FileProcessor.File.DomainEvents\FileProcessor.File.DomainEvents.csproj" />
<ProjectReference Include="..\FIleProcessor.Models\FIleProcessor.Models.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

<ItemGroup>
<PackageReference Include="Grpc.Net.Client" Version="2.47.0" />
<PackageReference Include="Shared.DomainDrivenDesign" Version="1.5.1" />
<PackageReference Include="Shared.EventStore" Version="1.5.1" />
<PackageReference Include="Shared.DomainDrivenDesign" Version="2022.12.0-beta4" />
<PackageReference Include="Shared.EventStore" Version="2022.12.0-beta4" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Shared.DomainDrivenDesign" Version="1.5.1" />
<PackageReference Include="Shared.DomainDrivenDesign" Version="2022.12.0-beta4" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<ItemGroup>
<PackageReference Include="Grpc.Net.Client" Version="2.47.0" />
<PackageReference Include="Shared.EventStore" Version="1.5.1" />
<PackageReference Include="Shared.EventStore" Version="2022.12.0-beta4" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="SecurityService.Client" Version="1.1.2-build20" />
<PackageReference Include="Shared" Version="1.5.1" />
<PackageReference Include="Shared.IntegrationTesting" Version="1.5.1" />
<PackageReference Include="Shared" Version="2022.12.0-beta4" />
<PackageReference Include="Shared.IntegrationTesting" Version="2022.12.0-beta4" />
<PackageReference Include="Shouldly" Version="4.1.0" />
<PackageReference Include="SpecFlow" Version="3.9.74" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.74" />
Expand Down
3 changes: 2 additions & 1 deletion FileProcessor/Bootstrapper/DomainEventHandlerRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public DomainEventHandlerRegistry()
});

this.AddSingleton<FileDomainEventHandler>();
this.AddSingleton<IDomainEventHandlerResolver, DomainEventHandlerResolver>();
this.For<IDomainEventHandlerResolver>().Use<DomainEventHandlerResolver>().Named("Main")
.Ctor<Dictionary<String, String[]>>().Is(eventHandlersConfiguration).Singleton();
}

#endregion
Expand Down
1 change: 0 additions & 1 deletion FileProcessor/FileProcessingWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using Microsoft.Extensions.Logging;
using Shared.EventStore.Aggregate;
using Shared.EventStore.EventStore;
using Shared.EventStore.Subscriptions;
using Shared.General;

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion FileProcessor/FileProcessor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.15.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.5" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Shared" Version="1.5.1" />
<PackageReference Include="Shared" Version="2022.12.0-beta4" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
Expand Down
1 change: 0 additions & 1 deletion FileProcessor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ namespace FileProcessor
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using Shared.EventStore.EventHandling;
using Shared.EventStore.Subscriptions;
using Shared.Logger;

[ExcludeFromCodeCoverage]
Expand Down
121 changes: 87 additions & 34 deletions FileProcessor/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,61 +244,114 @@ public static IServiceCollection AddInSecureEventStoreClient(
}
};

static Action<TraceEventType, String> concurrentLog = (tt, message) => log(tt, "CONCURRENT", message);
static Action<TraceEventType, String> mainLog = (tt, message) => Extensions.log(tt, "MAIN", message);
static Action<TraceEventType, String> orderedLog = (tt, message) => Extensions.log(tt, "ORDERED", message);

public static void PreWarm(this IApplicationBuilder applicationBuilder)
{
Startup.LoadTypes();

//SubscriptionWorker worker = new SubscriptionWorker()
var internalSubscriptionService = Boolean.Parse(ConfigurationReader.GetValue("InternalSubscriptionService"));
IConfigurationSection subscriptionConfigSection = Startup.Configuration.GetSection("AppSettings:SubscriptionConfiguration");
SubscriptionWorkersRoot subscriptionWorkersRoot = new SubscriptionWorkersRoot();
subscriptionConfigSection.Bind(subscriptionWorkersRoot);

if (internalSubscriptionService)
if (subscriptionWorkersRoot.InternalSubscriptionService)
{
String eventStoreConnectionString = ConfigurationReader.GetValue("EventStoreSettings", "ConnectionString");
Int32 inflightMessages = Int32.Parse(ConfigurationReader.GetValue("AppSettings", "InflightMessages"));
Int32 persistentSubscriptionPollingInSeconds = Int32.Parse(ConfigurationReader.GetValue("AppSettings", "PersistentSubscriptionPollingInSeconds"));
String filter = ConfigurationReader.GetValue("AppSettings", "InternalSubscriptionServiceFilter");
String ignore = ConfigurationReader.GetValue("AppSettings", "InternalSubscriptionServiceIgnore");
String streamName = ConfigurationReader.GetValue("AppSettings", "InternalSubscriptionFilterOnStreamName");
Int32 cacheDuration = Int32.Parse(ConfigurationReader.GetValue("AppSettings", "InternalSubscriptionServiceCacheDuration"));

ISubscriptionRepository subscriptionRepository = SubscriptionRepository.Create(eventStoreConnectionString, cacheDuration);

((SubscriptionRepository)subscriptionRepository).Trace += (sender, s) => Extensions.log(TraceEventType.Information, "REPOSITORY", s);
ISubscriptionRepository subscriptionRepository = SubscriptionRepository.Create(eventStoreConnectionString, subscriptionWorkersRoot.InternalSubscriptionServiceCacheDuration);
((SubscriptionRepository)subscriptionRepository).Trace += (sender,
s) => Extensions.log(TraceEventType.Information, "REPOSITORY", s);

// init our SubscriptionRepository
subscriptionRepository.PreWarm(CancellationToken.None).Wait();

var eventHandlerResolver = Startup.ServiceProvider.GetService<IDomainEventHandlerResolver>();

SubscriptionWorker concurrentSubscriptions = SubscriptionWorker.CreateConcurrentSubscriptionWorker(eventStoreConnectionString, eventHandlerResolver, subscriptionRepository, inflightMessages, persistentSubscriptionPollingInSeconds);

concurrentSubscriptions.Trace += (_, args) => concurrentLog(TraceEventType.Information, args.Message);
concurrentSubscriptions.Warning += (_, args) => concurrentLog(TraceEventType.Warning, args.Message);
concurrentSubscriptions.Error += (_, args) => concurrentLog(TraceEventType.Error, args.Message);

if (!String.IsNullOrEmpty(ignore))
List<SubscriptionWorker> workers = ConfigureSubscriptions(subscriptionRepository, subscriptionWorkersRoot);
foreach (SubscriptionWorker subscriptionWorker in workers)
{
concurrentSubscriptions = concurrentSubscriptions.IgnoreSubscriptions(ignore);
subscriptionWorker.StartAsync(CancellationToken.None).Wait();
}
}
}

if (!String.IsNullOrEmpty(filter))
{
//NOTE: Not overly happy with this design, but
//the idea is if we supply a filter, this overrides ignore
concurrentSubscriptions = concurrentSubscriptions.FilterSubscriptions(filter)
.IgnoreSubscriptions(null);
private static List<SubscriptionWorker> ConfigureSubscriptions(ISubscriptionRepository subscriptionRepository, SubscriptionWorkersRoot configuration)
{
List<SubscriptionWorker> workers = new List<SubscriptionWorker>();

}
foreach (SubscriptionWorkerConfig configurationSubscriptionWorker in configuration.SubscriptionWorkers)
{
if (configurationSubscriptionWorker.Enabled == false)
continue;

if (!String.IsNullOrEmpty(streamName))
if (configurationSubscriptionWorker.IsOrdered)
{
concurrentSubscriptions = concurrentSubscriptions.FilterByStreamName(streamName);
IDomainEventHandlerResolver eventHandlerResolver = Startup.Container.GetInstance<IDomainEventHandlerResolver>("Ordered");
SubscriptionWorker worker = SubscriptionWorker.CreateOrderedSubscriptionWorker(Startup.EventStoreClientSettings,
eventHandlerResolver,
subscriptionRepository,
configuration.PersistentSubscriptionPollingInSeconds);
worker.Trace += (_,
args) => Extensions.orderedLog(TraceEventType.Information, args.Message);
worker.Warning += (_,
args) => Extensions.orderedLog(TraceEventType.Warning, args.Message);
worker.Error += (_,
args) => Extensions.orderedLog(TraceEventType.Error, args.Message);
worker.SetIgnoreGroups(configurationSubscriptionWorker.IgnoreGroups);
worker.SetIgnoreStreams(configurationSubscriptionWorker.IgnoreStreams);
worker.SetIncludeGroups(configurationSubscriptionWorker.IncludeGroups);
worker.SetIncludeStreams(configurationSubscriptionWorker.IncludeStreams);
workers.Add(worker);
}
else
{
for (Int32 i = 0; i < configurationSubscriptionWorker.InstanceCount; i++)
{
IDomainEventHandlerResolver eventHandlerResolver = Startup.Container.GetInstance<IDomainEventHandlerResolver>("Main");
SubscriptionWorker worker = SubscriptionWorker.CreateSubscriptionWorker(Startup.EventStoreClientSettings,
eventHandlerResolver,
subscriptionRepository,
configurationSubscriptionWorker.InflightMessages,
configuration.PersistentSubscriptionPollingInSeconds);

worker.Trace += (_,
args) => Extensions.mainLog(TraceEventType.Information, args.Message);
worker.Warning += (_,
args) => Extensions.mainLog(TraceEventType.Warning, args.Message);
worker.Error += (_,
args) => Extensions.mainLog(TraceEventType.Error, args.Message);

worker.SetIgnoreGroups(configurationSubscriptionWorker.IgnoreGroups);
worker.SetIgnoreStreams(configurationSubscriptionWorker.IgnoreStreams);
worker.SetIncludeGroups(configurationSubscriptionWorker.IncludeGroups);
worker.SetIncludeStreams(configurationSubscriptionWorker.IncludeStreams);

workers.Add(worker);
}
}

concurrentSubscriptions.StartAsync(CancellationToken.None).Wait();
}

return workers;
}
}

public class SubscriptionWorkersRoot
{
public Boolean InternalSubscriptionService { get; set; }
public Int32 PersistentSubscriptionPollingInSeconds { get; set; }
public Int32 InternalSubscriptionServiceCacheDuration { get; set; }
public List<SubscriptionWorkerConfig> SubscriptionWorkers { get; set; }
}

public class SubscriptionWorkerConfig
{
public String WorkerName { get; set; }
public String IncludeGroups { get; set; }
public String IgnoreGroups { get; set; }
public String IncludeStreams { get; set; }
public String IgnoreStreams { get; set; }
public Boolean Enabled { get; set; }
public Int32 InflightMessages { get; set; }
public Int32 InstanceCount { get; set; }
public Boolean IsOrdered { get; set; }
}
}
17 changes: 16 additions & 1 deletion FileProcessor/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@
},
"AppSettings": {
"FileProfilePollingWindowInSeconds": 20,
"InternalSubscriptionServiceFilter": "File Processor",
"SubscriptionConfiguration": {
"InternalSubscriptionService": "true",
"PersistentSubscriptionPollingInSeconds": 480,
"InternalSubscriptionServiceCacheDuration": 120,
"SubscriptionWorkers": [
{
"WorkerName": "File Processor Main",
"IncludeGroups": "File Processor",
"IgnoreGroups": "Ordered,local-",
"Enabled": true,
"InflightMessages": 100,
"IsOrdered": false,
"InstanceCount": 1
}
]
},
"ClientId": "serviceClient",
"ClientSecret": "d192cbc46d834d0da90e8a9d50ded543",
"EventHandlerConfiguration": {
Expand Down