Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: consume StreetNameWasReaddressed #771

Merged
merged 13 commits into from
May 17, 2024
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
2 changes: 2 additions & 0 deletions ParcelRegistry.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/AddImportsToDeepestScope/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="aa_bb" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=a0b4bc4d_002Dd13b_002D4a37_002Db37e_002Dc9c6864e4302/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Any" AccessRightKinds="Any" Description="Types and namespaces"&gt;&lt;ElementKinds&gt;&lt;Kind Name="NAMESPACE" /&gt;&lt;Kind Name="CLASS" /&gt;&lt;Kind Name="STRUCT" /&gt;&lt;Kind Name="ENUM" /&gt;&lt;Kind Name="DELEGATE" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="aa_bb" /&gt;&lt;/Policy&gt;&lt;/Policy&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/Editor/UseCamelHumps/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/Environment/InlayHints/CppParameterNameHintsOptions2/ShowParameterNameHints/@EntryValue">Never</s:String>
<s:String x:Key="/Default/Environment/InlayHints/CSharpParameterNameHintsOptions/ShowParameterNameHints/@EntryValue">Never</s:String>
Expand All @@ -26,4 +27,5 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EPredefinedNamingRulesToUserRulesUpgrade/@EntryIndexedValue">True</s:Boolean>
</wpf:ResourceDictionary>
20 changes: 10 additions & 10 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ nuget Be.Vlaanderen.Basisregisters.Projector 15.0.0

nuget Be.Vlaanderen.Basisregisters.Crab 4.0.0

nuget Be.Vlaanderen.Basisregisters.GrAr.Common 21.1.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Notifications 21.1.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Contracts 21.1.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Edit 21.1.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Import 21.1.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Legacy 21.1.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Provenance 21.1.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Provenance.AcmIdm 21.1.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Extracts 21.1.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Oslo 21.1.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Common 21.6.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Notifications 21.6.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Contracts 21.6.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Edit 21.6.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Import 21.6.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Legacy 21.6.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Provenance 21.6.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Provenance.AcmIdm 21.6.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Extracts 21.6.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Oslo 21.6.0

nuget Be.Vlaanderen.Basisregisters.MessageHandling.AwsSqs.Simple 5.0.1
nuget Be.Vlaanderen.Basisregisters.MessageHandling.Kafka.Simple 5.0.1
Expand Down
32 changes: 15 additions & 17 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -253,20 +253,18 @@ NUGET
Autofac.Extensions.DependencyInjection (>= 9.0)
Be.Vlaanderen.Basisregisters.EventHandling (5.0)
Be.Vlaanderen.Basisregisters.Generators.Guid.Deterministic (4.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.1)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.6)
Be.Vlaanderen.Basisregisters.AggregateSource (>= 9.0.1)
Be.Vlaanderen.Basisregisters.CommandHandling (>= 9.0.1)
NetTopologySuite (>= 2.5)
NodaTime (>= 3.1.11)
Be.Vlaanderen.Basisregisters.GrAr.Contracts (21.1)
Be.Vlaanderen.Basisregisters.AggregateSource (>= 9.0.1)
NodaTime (>= 3.1.11)
Be.Vlaanderen.Basisregisters.GrAr.Edit (21.1)
Be.Vlaanderen.Basisregisters.GrAr.Contracts (21.6)
Be.Vlaanderen.Basisregisters.GrAr.Edit (21.6)
NetTopologySuite (>= 2.5)
Be.Vlaanderen.Basisregisters.GrAr.Extracts (21.1)
Be.Vlaanderen.Basisregisters.GrAr.Extracts (21.6)
Be.Vlaanderen.Basisregisters.Api (>= 21.0)
Be.Vlaanderen.Basisregisters.Shaperon (>= 10.0.2)
Be.Vlaanderen.Basisregisters.GrAr.Import (21.1)
Be.Vlaanderen.Basisregisters.GrAr.Import (21.6)
Autofac (>= 8.0)
Be.Vlaanderen.Basisregisters.AggregateSource.SqlStreamStore (>= 9.0.1)
Be.Vlaanderen.Basisregisters.CommandHandling (>= 9.0.1)
Expand All @@ -281,31 +279,31 @@ NUGET
Serilog (>= 3.1.1)
Serilog.Extensions.Logging (>= 8.0)
System.Threading.Tasks.Dataflow (>= 8.0)
Be.Vlaanderen.Basisregisters.GrAr.Legacy (21.1)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.1)
Be.Vlaanderen.Basisregisters.GrAr.Legacy (21.6)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.6)
Be.Vlaanderen.Basisregisters.Utilities.Rfc3339DateTimeOffset (>= 4.0)
Newtonsoft.Json (>= 13.0.3)
Be.Vlaanderen.Basisregisters.GrAr.Notifications (21.1)
Be.Vlaanderen.Basisregisters.GrAr.Notifications (21.6)
AWSSDK.SimpleNotificationService (>= 3.7.301.3)
System.Text.Json (>= 8.0.3)
Be.Vlaanderen.Basisregisters.GrAr.Oslo (21.1)
Be.Vlaanderen.Basisregisters.GrAr.Oslo (21.6)
Be.Vlaanderen.Basisregisters.AspNetCore.Mvc.Formatters.Json (>= 5.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.1)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.6)
Be.Vlaanderen.Basisregisters.Utilities.Rfc3339DateTimeOffset (>= 4.0)
Microsoft.Extensions.Configuration (>= 8.0)
Microsoft.Extensions.Http.Polly (>= 8.0.3)
Newtonsoft.Json (>= 13.0.3)
Be.Vlaanderen.Basisregisters.GrAr.Provenance (21.1)
Be.Vlaanderen.Basisregisters.GrAr.Provenance (21.6)
Be.Vlaanderen.Basisregisters.CommandHandling (>= 9.0.1)
Be.Vlaanderen.Basisregisters.Crab (>= 4.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.1)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.6)
Microsoft.CSharp (>= 4.7)
Be.Vlaanderen.Basisregisters.GrAr.Provenance.AcmIdm (21.1)
Be.Vlaanderen.Basisregisters.GrAr.Provenance.AcmIdm (21.6)
Be.Vlaanderen.Basisregisters.Auth.AcmIdm (>= 2.0)
Be.Vlaanderen.Basisregisters.CommandHandling (>= 9.0.1)
Be.Vlaanderen.Basisregisters.Crab (>= 4.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.1)
Be.Vlaanderen.Basisregisters.GrAr.Provenance (21.1)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.6)
Be.Vlaanderen.Basisregisters.GrAr.Provenance (21.6)
Microsoft.CSharp (>= 4.7)
Be.Vlaanderen.Basisregisters.MessageHandling.AwsSqs.Simple (5.0.1)
AWSSDK.Core (>= 3.7.302.15)
Expand Down
15 changes: 14 additions & 1 deletion src/ParcelRegistry.Consumer.Address.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace ParcelRegistry.Consumer.Address.Console
using Autofac;
using Autofac.Extensions.DependencyInjection;
using Be.Vlaanderen.Basisregisters.Aws.DistributedMutex;
using Be.Vlaanderen.Basisregisters.CommandHandling.Idempotency;
using Be.Vlaanderen.Basisregisters.EventHandling;
using Be.Vlaanderen.Basisregisters.MessageHandling.Kafka;
using Be.Vlaanderen.Basisregisters.MessageHandling.Kafka.Consumer;
using Destructurama;
using Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -25,6 +25,7 @@ namespace ParcelRegistry.Consumer.Address.Console
using Serilog;
using Serilog.Debugging;
using Serilog.Extensions.Logging;
using MigrationsHelper = Infrastructure.MigrationsHelper;

public sealed class Program
{
Expand Down Expand Up @@ -145,6 +146,18 @@ public static async Task Main(string[] args)
.As<IIdempotentConsumer<ConsumerAddressContext>>()
.SingleInstance();

services.ConfigureIdempotency(
hostContext.Configuration.GetSection(IdempotencyConfiguration.Section)
.Get<IdempotencyConfiguration>()!.ConnectionString!,
new IdempotencyMigrationsTableInfo(Schema.Import),
new IdempotencyTableInfo(Schema.Import),
loggerFactory);

builder.RegisterType<IdempotentCommandHandler>()
.As<IIdempotentCommandHandler>()
.AsSelf()
.InstancePerLifetimeScope();

builder
.RegisterModule(new EditModule(hostContext.Configuration))
.RegisterModule(new BackOfficeModule(hostContext.Configuration, services, loggerFactory, ServiceLifetime.Transient));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"BackOffice": "Server=(localdb)\\mssqllocaldb;Database=EFProviders.InMemory.ParcelRegistry;Trusted_Connection=True;TrustServerCertificate=True;"
},

"Idempotency": {
"ConnectionString": "Server=(localdb)\\mssqllocaldb;Database=EFProviders.InMemory.ParcelRegistry;Trusted_Connection=True;TrustServerCertificate=True;"
},

"Kafka": {
"BootstrapServers": "localhost:29092/"
},
Expand Down
6 changes: 5 additions & 1 deletion src/ParcelRegistry.Consumer.Address/BackOfficeConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ namespace ParcelRegistry.Consumer.Address
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Parcel;
using Projections;

public sealed class BackOfficeConsumer : BackgroundService
{
private readonly ILifetimeScope _lifetimeScope;
private readonly IHostApplicationLifetime _hostApplicationLifetime;
private readonly IDbContextFactory<BackOfficeContext> _backOfficeContextFactory;
private readonly IParcels _parcels;
private readonly ILoggerFactory _loggerFactory;
private readonly IIdempotentConsumer<ConsumerAddressContext> _kafkaIdemIdompotencyConsumer;
private readonly ILogger<BackOfficeConsumer> _logger;
Expand All @@ -25,12 +27,14 @@ public BackOfficeConsumer(
ILifetimeScope lifetimeScope,
IHostApplicationLifetime hostApplicationLifetime,
IDbContextFactory<BackOfficeContext> backOfficeContextFactory,
IParcels parcels,
ILoggerFactory loggerFactory,
IIdempotentConsumer<ConsumerAddressContext> kafkaIdemIdompotencyConsumer)
{
_lifetimeScope = lifetimeScope;
_hostApplicationLifetime = hostApplicationLifetime;
_backOfficeContextFactory = backOfficeContextFactory;
_parcels = parcels;
_loggerFactory = loggerFactory;
_kafkaIdemIdompotencyConsumer = kafkaIdemIdompotencyConsumer;

Expand All @@ -45,7 +49,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

var commandHandlingProjector = new ConnectedProjector<CommandHandler>(
Resolve.WhenEqualToHandlerMessageType(
new CommandHandlingKafkaProjection(_backOfficeContextFactory).Handlers));
new CommandHandlingKafkaProjection(_backOfficeContextFactory, _parcels).Handlers));

var commandHandler = new CommandHandler(_lifetimeScope, _loggerFactory);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
namespace ParcelRegistry.Consumer.Address.Projections
{
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Autofac;
using Be.Vlaanderen.Basisregisters.CommandHandling;
using Be.Vlaanderen.Basisregisters.CommandHandling.Idempotency;
using Be.Vlaanderen.Basisregisters.GrAr.Provenance;
using Microsoft.Extensions.Logging;

Expand All @@ -30,5 +32,22 @@ public virtual async Task Handle<T>(T command, CancellationToken cancellationTok

_logger.LogDebug($"Handled {command.GetType().FullName}");
}

public virtual async Task HandleIdempotent<T>(T command, CancellationToken cancellationToken)
where T : class, IHasCommandProvenance
{
_logger.LogDebug($"Idempotently handling {command.GetType().FullName}");

await using var scope = _container.BeginLifetimeScope();

var resolver = scope.Resolve<IIdempotentCommandHandler>();
_ = await resolver.Dispatch(
command.CreateCommandId(),
command,
new Dictionary<string, object>(),
cancellationToken: cancellationToken);

_logger.LogDebug($"Idempotently handled {command.GetType().FullName}");
}
}
}
Loading
Loading