From cb3b7584beb7730af8076072f67a33bcf2e7ff09 Mon Sep 17 00:00:00 2001 From: Koen Metsu Date: Wed, 24 Jan 2024 22:31:22 +0100 Subject: [PATCH] fix: or-1349 don't use bus --- .../ConfigureMartenExtensions.cs | 7 +- .../Search/MartenEventsConsumer.cs | 96 +++++++++++++++++-- 2 files changed, 95 insertions(+), 8 deletions(-) diff --git a/src/AssociationRegistry.Admin.ProjectionHost/Infrastructure/Program/WebApplicationBuilder/ConfigureMartenExtensions.cs b/src/AssociationRegistry.Admin.ProjectionHost/Infrastructure/Program/WebApplicationBuilder/ConfigureMartenExtensions.cs index 6a72e9f55..367477bea 100644 --- a/src/AssociationRegistry.Admin.ProjectionHost/Infrastructure/Program/WebApplicationBuilder/ConfigureMartenExtensions.cs +++ b/src/AssociationRegistry.Admin.ProjectionHost/Infrastructure/Program/WebApplicationBuilder/ConfigureMartenExtensions.cs @@ -15,6 +15,7 @@ namespace AssociationRegistry.Admin.ProjectionHost.Infrastructure.Program.WebApp using Projections.Detail; using Projections.Historiek; using Projections.Search; +using Projections.Search.DuplicateDetection; using Projections.Search.Zoeken; using Schema.Detail; using Schema.Historiek; @@ -94,7 +95,11 @@ static JsonNetSerializer CreateCustomMartenSerializer() opts.Projections.Add( new MartenSubscription( new MartenEventsConsumer( - serviceProvider.GetRequiredService() + serviceProvider.GetRequiredService(), + new DuplicateDetectionProjectionHandler( + serviceProvider.GetRequiredService()), + new BeheerZoekProjectionHandler( + serviceProvider.GetRequiredService()) ) ), ProjectionLifecycle.Async, diff --git a/src/AssociationRegistry.Admin.ProjectionHost/Projections/Search/MartenEventsConsumer.cs b/src/AssociationRegistry.Admin.ProjectionHost/Projections/Search/MartenEventsConsumer.cs index f56e01c39..588525ec7 100644 --- a/src/AssociationRegistry.Admin.ProjectionHost/Projections/Search/MartenEventsConsumer.cs +++ b/src/AssociationRegistry.Admin.ProjectionHost/Projections/Search/MartenEventsConsumer.cs @@ -1,16 +1,26 @@ namespace AssociationRegistry.Admin.ProjectionHost.Projections.Search; +using DuplicateDetection; +using Events; using Marten.Events; using Wolverine; using Wolverine.Runtime.Routing; +using Zoeken; +using IEvent = Framework.IEvent; public class MartenEventsConsumer : IMartenEventsConsumer { private readonly IMessageBus _bus; + private readonly DuplicateDetectionProjectionHandler _duplicateDetectionProjectionHandler; + private readonly BeheerZoekProjectionHandler _zoekProjectionHandler; - public MartenEventsConsumer(IMessageBus bus) + public MartenEventsConsumer(IMessageBus bus, + DuplicateDetectionProjectionHandler duplicateDetectionProjectionHandler, + BeheerZoekProjectionHandler zoekProjectionHandler) { _bus = bus; + _duplicateDetectionProjectionHandler = duplicateDetectionProjectionHandler; + _zoekProjectionHandler = zoekProjectionHandler; } public async Task ConsumeAsync(IReadOnlyList streamActions) @@ -20,13 +30,85 @@ public async Task ConsumeAsync(IReadOnlyList streamActions) var eventEnvelope = (IEventEnvelope)Activator.CreateInstance(typeof(EventEnvelope<>).MakeGenericType(@event.EventType), @event)!; - try + switch (@event.EventType.Name) { - await _bus.InvokeAsync(eventEnvelope); - } - catch (IndeterminateRoutesException) - { - //ignore + + case nameof(DoelgroepWerdGewijzigd): + await _zoekProjectionHandler.Handle((EventEnvelope)eventEnvelope); + break; + + case nameof(FeitelijkeVerenigingWerdGeregistreerd): + await _duplicateDetectionProjectionHandler.Handle((EventEnvelope)eventEnvelope); + await _zoekProjectionHandler.Handle((EventEnvelope)eventEnvelope); + break; + + case nameof(HoofdactiviteitenVerenigingsloketWerdenGewijzigd): + await _duplicateDetectionProjectionHandler.Handle((EventEnvelope)eventEnvelope); + await _zoekProjectionHandler.Handle((EventEnvelope)eventEnvelope); + break; + + case nameof(KorteNaamWerdGewijzigd): + await _duplicateDetectionProjectionHandler.Handle((EventEnvelope)eventEnvelope); + await _zoekProjectionHandler.Handle((EventEnvelope)eventEnvelope); + break; + + case nameof(LocatieWerdGewijzigd): + await _duplicateDetectionProjectionHandler.Handle((EventEnvelope)eventEnvelope); + await _zoekProjectionHandler.Handle((EventEnvelope)eventEnvelope); + break; + + case nameof(LocatieWerdToegevoegd): + await _duplicateDetectionProjectionHandler.Handle((EventEnvelope)eventEnvelope); + await _zoekProjectionHandler.Handle((EventEnvelope)eventEnvelope); + break; + + case nameof(LocatieWerdVerwijderd): + await _duplicateDetectionProjectionHandler.Handle((EventEnvelope)eventEnvelope); + await _zoekProjectionHandler.Handle((EventEnvelope)eventEnvelope); + break; + + + case nameof(MaatschappelijkeZetelVolgensKBOWerdGewijzigd): + await _zoekProjectionHandler.Handle((EventEnvelope)eventEnvelope); + break; + + case nameof(MaatschappelijkeZetelWerdOvergenomenUitKbo): + await _duplicateDetectionProjectionHandler.Handle((EventEnvelope)eventEnvelope); + await _zoekProjectionHandler.Handle((EventEnvelope)eventEnvelope); + break; + + case nameof(NaamWerdGewijzigd): + await _duplicateDetectionProjectionHandler.Handle((EventEnvelope)eventEnvelope); + await _zoekProjectionHandler.Handle((EventEnvelope)eventEnvelope); + break; + + case nameof(RoepnaamWerdGewijzigd): + await _zoekProjectionHandler.Handle((EventEnvelope)eventEnvelope); + break; + + + case nameof(VerenigingMetRechtspersoonlijkheidWerdGeregistreerd): + await _duplicateDetectionProjectionHandler.Handle((EventEnvelope)eventEnvelope); + await _zoekProjectionHandler.Handle((EventEnvelope)eventEnvelope); + break; + + case nameof(VerenigingWerdGestopt): + await _duplicateDetectionProjectionHandler.Handle((EventEnvelope)eventEnvelope); + await _zoekProjectionHandler.Handle((EventEnvelope)eventEnvelope); + break; + + case nameof(VerenigingWerdIngeschrevenInPubliekeDatastroom): + await _zoekProjectionHandler.Handle((EventEnvelope)eventEnvelope); + break; + + case nameof(VerenigingWerdUitgeschrevenUitPubliekeDatastroom): + await _zoekProjectionHandler.Handle((EventEnvelope)eventEnvelope); + break; + + case nameof(VerenigingWerdVerwijderd): + await _duplicateDetectionProjectionHandler.Handle((EventEnvelope)eventEnvelope); + await _zoekProjectionHandler.Handle((EventEnvelope)eventEnvelope); + break; } } }