From f88d694f4e1aef445dc61d0fa930dcb64b3e02b5 Mon Sep 17 00:00:00 2001 From: fraliv13 <5892139+fraliv13@users.noreply.github.com> Date: Tue, 19 Jan 2021 15:19:17 +0200 Subject: [PATCH] NBB refactor messaging data contracts, process manager state, cleanup unused features (#112) * Removed EventStoreHost and GetEventStore * Removed SerializedMessage, IMessage * Removed NBB.Resiliency project * Moved resiliency policies to messaging host * Process manager state refactoring * Moved messaging data contracts to MessagingAbstractions --- NBB.EventStore.slnf | 7 +- NBB.Messaging.slnf | 1 - NBB.sln | 38 ------ .../NBB.Contracts.Application.Commands.csproj | 1 - .../NBB.Contracts.PublishedLanguage.csproj | 1 - .../NBB.Contracts.Worker.csproj | 1 - .../NBB.Contracts.Worker/Program.cs | 3 - .../NBB.Invoices.Application.Commands.csproj | 1 - .../NBB.Invoices.PublishedLanguage.csproj | 1 - .../NBB.Invoices.Worker/Program.cs | 3 - .../NBB.Payments.Application.Commands.csproj | 1 - .../NBB.Payments.PublishedLanguage.csproj | 1 - .../NBB.Payments.Worker/Program.cs | 3 - samples/Monolith/NBB.Mono/Startup.cs | 3 - .../SubscriberLoggingMiddleware.cs | 2 +- .../OrderProcessManager.cs | 7 +- .../OrderProcessManagerData.cs | 6 +- .../ProcessManagerSample.csproj | 1 - .../ProcessManagerSample/Program.cs | 2 +- .../ProcessManagerSample/Startup.cs | 3 - .../NBB.Application.MediatR.csproj | 1 - src/Core/NBB.Core.Abstractions/SetOnce.cs | 31 ----- .../EventStoreHostBuilder.cs | 40 ------ .../EventStoreSubscriberService.cs | 47 ------- .../NBB.EventStore.Host.csproj | 22 ---- .../Pipeline/DefaultResiliencyMiddleware.cs | 48 ------- .../Pipeline/EventPipelineExtensions.cs | 20 --- .../Pipeline/ExceptionHandlingMiddleware.cs | 46 ------- .../Pipeline/MediatRMiddleware.cs | 29 ----- .../ServiceCollectionExtensions.cs | 12 -- .../DependencyInjectionExtensions.cs | 18 --- .../NBB.GetEventStore/GetEventStoreClient.cs | 100 -------------- .../GetEventStoreSubscriber.cs | 89 ------------- .../Internal/EventMetadata.cs | 34 ----- .../NBB.GetEventStore/Internal/ISerDes.cs | 12 -- .../NBB.GetEventStore/Internal/SerDes.cs | 32 ----- .../NBB.GetEventStore.csproj | 26 ---- .../DefaultMessageTypeRegistry.cs | 1 - .../DefaultTopicRegistry.cs | 1 - .../IMessageBusPublisher.cs | 21 ++- .../IMessageBusSubscriber.cs | 3 +- .../IMessageSerDes.cs | 20 ++- .../MessageBusPublisher.cs | 4 +- .../MessageBusSubscriber.cs | 1 - .../MessageTypeIdAttribute.cs | 2 +- .../MessagingContext.cs | 4 +- .../MessagingEnvelope.cs | 2 +- .../MessagingEnvelopeExtensions.cs | 3 +- .../NBB.Messaging.Abstractions.csproj | 3 +- .../NewtonsoftJsonMessageSerDes.cs | 1 - .../TopicNameAttribute.cs | 2 +- .../TopicNameResolverAttribute.cs | 2 +- .../NBB.Messaging.DataContracts/IMessage.cs | 6 - .../NBB.Messaging.DataContracts.csproj | 28 ---- .../SerializedMessage.cs | 25 ---- .../Builder/MessagingHostBuilder.cs | 2 +- .../MessageBusSubscriberService.cs | 3 +- .../MessagingContextBusPublisherDecorator.cs | 1 - .../CorrelationMiddleware.cs | 1 - .../DefaultResiliencyMiddleware.cs | 43 +++--- .../ExceptionHandlingMiddleware.cs | 2 +- .../MessagingPipeline/MediatRMiddleware.cs | 2 +- .../MessagingPipelineExtensions.cs | 2 +- .../MessagingTopicSubscriberService.cs | 1 - .../NBB.Messaging.Host.csproj | 2 +- ...ultiTenancyMessageBusPublisherDecorator.cs | 1 - .../TenantMiddleware.cs | 2 +- .../OpenTracingPublisherDecorator.cs | 1 - .../Subscriber/MessagingPipelineExtensions.cs | 2 +- .../Subscriber/OpenTracingMiddleware.cs | 1 - .../Builder/AbstractDefinition.cs | 3 +- .../Builder/EventActivitySet.cs | 2 - .../Builder/EventActivitySetBuilder.cs | 1 - .../Builder/EventCorrelationBuilder.cs | 3 +- .../Delegates.cs | 8 +- .../IDefinition.cs | 1 - .../InstanceData.cs | 1 - .../NBB.ProcessManager.Runtime/Instance.cs | 5 +- .../Persistence/IInstanceDataRepository.cs | 6 +- .../Persistence/InstanceDataRepository.cs | 4 +- .../ProcessExecutionCoordinator.cs | 2 +- .../ProcessManagerNotificationHandler.cs | 2 +- .../IResiliencyPolicyProvider.cs | 11 -- .../NBB.Resiliency/NBB.Resiliency.csproj | 17 --- .../ResiliencyPolicyProvider.cs | 31 ----- .../ServiceCollectionExtensions.cs | 12 -- .../EventStoreBenchmark.cs | 30 ----- .../EventStoreBenchmarks.csproj | 2 - .../EventStoreDBIntegrationTests.cs | 24 ++-- .../EventStoreMessagingIntegrationTests.cs | 117 ----------------- .../NBB.EventStore.IntegrationTests.csproj | 1 - .../GetEventStoreSubscriberTests.cs | 67 ---------- .../NBB.GetEventStore.Tests.csproj | 27 ---- .../MessageSerDesTests.cs | 1 - .../MessageTypeRegistryTests.cs | 1 - .../TopicRegistryTests.cs | 1 - .../NBB.Messaging.DataContracts.Tests.csproj | 1 - .../MessageBusSubscriberServceTests.cs | 1 - .../MessagingHostBuilderTests.cs | 2 - .../CorrelationMiddlewareTests.cs | 14 +- .../DefaultResiliencyMiddlewareTests.cs | 98 ++------------ .../ExceptionHandlingMiddlewareTests.cs | 19 +-- .../MediatRMiddlewareTests.cs | 15 ++- .../MessagingPipelineExtensionsTests.cs | 2 +- .../MessagingTopicSubscriberServiceTests.cs | 1 - .../StorageTests.cs | 3 +- .../MessageBusPublisherDecoratorTests.cs | 1 - ...nantIdHeaderMessagingTokenResolverTests.cs | 1 - .../ProcessManagerInstanceUnitTests.cs | 122 +++++++----------- 109 files changed, 188 insertions(+), 1360 deletions(-) delete mode 100644 src/Core/NBB.Core.Abstractions/SetOnce.cs delete mode 100644 src/EventStore/NBB.EventStore.Host/EventStoreHostBuilder.cs delete mode 100644 src/EventStore/NBB.EventStore.Host/EventStoreSubscriberService.cs delete mode 100644 src/EventStore/NBB.EventStore.Host/NBB.EventStore.Host.csproj delete mode 100644 src/EventStore/NBB.EventStore.Host/Pipeline/DefaultResiliencyMiddleware.cs delete mode 100644 src/EventStore/NBB.EventStore.Host/Pipeline/EventPipelineExtensions.cs delete mode 100644 src/EventStore/NBB.EventStore.Host/Pipeline/ExceptionHandlingMiddleware.cs delete mode 100644 src/EventStore/NBB.EventStore.Host/Pipeline/MediatRMiddleware.cs delete mode 100644 src/EventStore/NBB.EventStore.Host/ServiceCollectionExtensions.cs delete mode 100644 src/EventStore/NBB.GetEventStore/DependencyInjectionExtensions.cs delete mode 100644 src/EventStore/NBB.GetEventStore/GetEventStoreClient.cs delete mode 100644 src/EventStore/NBB.GetEventStore/GetEventStoreSubscriber.cs delete mode 100644 src/EventStore/NBB.GetEventStore/Internal/EventMetadata.cs delete mode 100644 src/EventStore/NBB.GetEventStore/Internal/ISerDes.cs delete mode 100644 src/EventStore/NBB.GetEventStore/Internal/SerDes.cs delete mode 100644 src/EventStore/NBB.GetEventStore/NBB.GetEventStore.csproj rename src/Messaging/{NBB.Messaging.DataContracts => NBB.Messaging.Abstractions}/MessageTypeIdAttribute.cs (83%) rename src/Messaging/{NBB.Messaging.DataContracts => NBB.Messaging.Abstractions}/MessagingEnvelope.cs (93%) rename src/Messaging/{NBB.Messaging.DataContracts => NBB.Messaging.Abstractions}/TopicNameAttribute.cs (91%) rename src/Messaging/{NBB.Messaging.DataContracts => NBB.Messaging.Abstractions}/TopicNameResolverAttribute.cs (86%) delete mode 100644 src/Messaging/NBB.Messaging.DataContracts/IMessage.cs delete mode 100644 src/Messaging/NBB.Messaging.DataContracts/NBB.Messaging.DataContracts.csproj delete mode 100644 src/Messaging/NBB.Messaging.DataContracts/SerializedMessage.cs delete mode 100644 src/Resiliency/NBB.Resiliency/IResiliencyPolicyProvider.cs delete mode 100644 src/Resiliency/NBB.Resiliency/NBB.Resiliency.csproj delete mode 100644 src/Resiliency/NBB.Resiliency/ResiliencyPolicyProvider.cs delete mode 100644 src/Resiliency/NBB.Resiliency/ServiceCollectionExtensions.cs delete mode 100644 test/Integration/NBB.EventStore.IntegrationTests/EventStoreMessagingIntegrationTests.cs delete mode 100644 test/UnitTests/EventStore/NBB.GetEventStore.Tests/GetEventStoreSubscriberTests.cs delete mode 100644 test/UnitTests/EventStore/NBB.GetEventStore.Tests/NBB.GetEventStore.Tests.csproj diff --git a/NBB.EventStore.slnf b/NBB.EventStore.slnf index e9d92639..d6aecc0a 100644 --- a/NBB.EventStore.slnf +++ b/NBB.EventStore.slnf @@ -5,17 +5,14 @@ "src\\EventStore\\NBB.EventStore.Abstractions\\NBB.EventStore.Abstractions.csproj", "src\\EventStore\\NBB.EventStore.AdoNet.Migrations\\NBB.EventStore.AdoNet.Migrations.csproj", "src\\EventStore\\NBB.EventStore.AdoNet\\NBB.EventStore.AdoNet.csproj", - "src\\EventStore\\NBB.EventStore.Host\\NBB.EventStore.Host.csproj", "src\\EventStore\\NBB.EventStore.InMemory\\NBB.EventStore.InMemory.csproj", "src\\EventStore\\NBB.EventStore.MessagingExtensions\\NBB.EventStore.MessagingExtensions.csproj", - "src\\EventStore\\NBB.EventStore\\NBB.EventStore.csproj", - "src\\EventStore\\NBB.GetEventStore\\NBB.GetEventStore.csproj", + "src\\EventStore\\NBB.EventStore\\NBB.EventStore.csproj", "src\\EventStore\\NBB.SQLStreamStore.Migrations\\NBB.SQLStreamStore.Migrations.csproj", "src\\EventStore\\NBB.SQLStreamStore\\NBB.SQLStreamStore.csproj", "test\\Integration\\NBB.EventStore.IntegrationTests\\NBB.EventStore.IntegrationTests.csproj", "test\\UnitTests\\EventStore\\NBB.EventStore.InMemory.Tests\\NBB.EventStore.InMemory.Tests.csproj", - "test\\UnitTests\\EventStore\\NBB.EventStore.Tests\\NBB.EventStore.Tests.csproj", - "test\\UnitTests\\EventStore\\NBB.GetEventStore.Tests\\NBB.GetEventStore.Tests.csproj" + "test\\UnitTests\\EventStore\\NBB.EventStore.Tests\\NBB.EventStore.Tests.csproj" ] } } \ No newline at end of file diff --git a/NBB.Messaging.slnf b/NBB.Messaging.slnf index 7d1d24a8..3cb77991 100644 --- a/NBB.Messaging.slnf +++ b/NBB.Messaging.slnf @@ -3,7 +3,6 @@ "path": "NBB.sln", "projects": [ "src\\Messaging\\NBB.Messaging.Abstractions\\NBB.Messaging.Abstractions.csproj", - "src\\Messaging\\NBB.Messaging.DataContracts\\NBB.Messaging.DataContracts.csproj", "src\\Messaging\\NBB.Messaging.Effects\\NBB.Messaging.Effects.csproj", "src\\Messaging\\NBB.Messaging.Host\\NBB.Messaging.Host.csproj", "src\\Messaging\\NBB.Messaging.InProcessMessaging\\NBB.Messaging.InProcessMessaging.csproj", diff --git a/NBB.sln b/NBB.sln index 6176ec15..ee3a2895 100644 --- a/NBB.sln +++ b/NBB.sln @@ -102,8 +102,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{14726095-D EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NBB.Core.Abstractions", "src\Core\NBB.Core.Abstractions\NBB.Core.Abstractions.csproj", "{2F591414-63E0-4CD8-AA1E-11132CC20EA9}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NBB.Messaging.DataContracts", "src\Messaging\NBB.Messaging.DataContracts\NBB.Messaging.DataContracts.csproj", "{602F852F-77EE-4335-BA45-170C32440575}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "EventStore", "EventStore", "{20C8482D-1525-47B0-B78B-09632892E8E4}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NBB.EventStore.Abstractions", "src\EventStore\NBB.EventStore.Abstractions\NBB.EventStore.Abstractions.csproj", "{7197E4CE-120D-4601-AA8B-F65B8DB2E883}" @@ -124,8 +122,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NBB.Messaging.Nats", "src\M EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NBB.Messaging.Abstractions.Tests", "test\UnitTests\Messaging\NBB.Messaging.Abstractions.Tests\NBB.Messaging.Abstractions.Tests.csproj", "{65743F60-F511-41E1-959B-D29FA3DB404D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NBB.GetEventStore", "src\EventStore\NBB.GetEventStore\NBB.GetEventStore.csproj", "{86A0DCDE-225B-4140-8195-A96F744573F0}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Monolith", "Monolith", "{34929B8F-4ED5-499C-A3AC-7ABE0F2F8FFE}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NBB.Mono", "samples\Monolith\NBB.Mono\NBB.Mono.csproj", "{34A864A3-C25C-4DFA-BCE8-173F72B572A3}" @@ -134,8 +130,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NBB.Messaging.InProcessMess EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NBB.Messaging.InProcessMessaging.Tests", "test\UnitTests\Messaging\NBB.Messaging.InProcessMessaging.Tests\NBB.Messaging.InProcessMessaging.Tests.csproj", "{2E99F025-BDC0-430E-AD2A-C81141AC2BCA}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NBB.GetEventStore.Tests", "test\UnitTests\EventStore\NBB.GetEventStore.Tests\NBB.GetEventStore.Tests.csproj", "{4831DD42-C73B-47DE-B5F6-9701F9773AD0}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NBB.SQLStreamStore", "src\EventStore\NBB.SQLStreamStore\NBB.SQLStreamStore.csproj", "{88B831EC-0DFE-40D7-9449-C4BDAE5B5512}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NBB.SQLStreamStore.Migrations", "src\EventStore\NBB.SQLStreamStore.Migrations\NBB.SQLStreamStore.Migrations.csproj", "{FC77C6B6-EAB3-4CC0-8BB0-535BC4CB2C5B}" @@ -182,12 +176,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NBB.Core.DependencyInjectio EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NBB.Messaging.Host", "src\Messaging\NBB.Messaging.Host\NBB.Messaging.Host.csproj", "{B15B9803-EB9D-4BA2-9B09-ACAE8F11252D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NBB.EventStore.Host", "src\EventStore\NBB.EventStore.Host\NBB.EventStore.Host.csproj", "{6CBD9972-ABB1-4E15-8FB7-8F377A081490}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Resiliency", "Resiliency", "{A6E20C85-DEC2-4540-83FA-84636CAEE734}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NBB.Resiliency", "src\Resiliency\NBB.Resiliency\NBB.Resiliency.csproj", "{4A9EFAB3-B798-4323-86C0-39D4C2C67C86}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DocFx", "docs\DocFx\DocFx.csproj", "{7C3851B7-151E-4DB4-8DC8-DED438D2A998}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NBB.Messaging.DataContracts.Tests", "test\UnitTests\Messaging\NBB.Messaging.DataContracts.Tests\NBB.Messaging.DataContracts.Tests.csproj", "{D4F5F69C-9A9F-425C-8DBA-B8053AE506B5}" @@ -433,10 +421,6 @@ Global {2F591414-63E0-4CD8-AA1E-11132CC20EA9}.Debug|Any CPU.Build.0 = Debug|Any CPU {2F591414-63E0-4CD8-AA1E-11132CC20EA9}.Release|Any CPU.ActiveCfg = Release|Any CPU {2F591414-63E0-4CD8-AA1E-11132CC20EA9}.Release|Any CPU.Build.0 = Release|Any CPU - {602F852F-77EE-4335-BA45-170C32440575}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {602F852F-77EE-4335-BA45-170C32440575}.Debug|Any CPU.Build.0 = Debug|Any CPU - {602F852F-77EE-4335-BA45-170C32440575}.Release|Any CPU.ActiveCfg = Release|Any CPU - {602F852F-77EE-4335-BA45-170C32440575}.Release|Any CPU.Build.0 = Release|Any CPU {7197E4CE-120D-4601-AA8B-F65B8DB2E883}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7197E4CE-120D-4601-AA8B-F65B8DB2E883}.Debug|Any CPU.Build.0 = Debug|Any CPU {7197E4CE-120D-4601-AA8B-F65B8DB2E883}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -465,10 +449,6 @@ Global {65743F60-F511-41E1-959B-D29FA3DB404D}.Debug|Any CPU.Build.0 = Debug|Any CPU {65743F60-F511-41E1-959B-D29FA3DB404D}.Release|Any CPU.ActiveCfg = Release|Any CPU {65743F60-F511-41E1-959B-D29FA3DB404D}.Release|Any CPU.Build.0 = Release|Any CPU - {86A0DCDE-225B-4140-8195-A96F744573F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {86A0DCDE-225B-4140-8195-A96F744573F0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {86A0DCDE-225B-4140-8195-A96F744573F0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {86A0DCDE-225B-4140-8195-A96F744573F0}.Release|Any CPU.Build.0 = Release|Any CPU {34A864A3-C25C-4DFA-BCE8-173F72B572A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {34A864A3-C25C-4DFA-BCE8-173F72B572A3}.Debug|Any CPU.Build.0 = Debug|Any CPU {34A864A3-C25C-4DFA-BCE8-173F72B572A3}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -481,10 +461,6 @@ Global {2E99F025-BDC0-430E-AD2A-C81141AC2BCA}.Debug|Any CPU.Build.0 = Debug|Any CPU {2E99F025-BDC0-430E-AD2A-C81141AC2BCA}.Release|Any CPU.ActiveCfg = Release|Any CPU {2E99F025-BDC0-430E-AD2A-C81141AC2BCA}.Release|Any CPU.Build.0 = Release|Any CPU - {4831DD42-C73B-47DE-B5F6-9701F9773AD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4831DD42-C73B-47DE-B5F6-9701F9773AD0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4831DD42-C73B-47DE-B5F6-9701F9773AD0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4831DD42-C73B-47DE-B5F6-9701F9773AD0}.Release|Any CPU.Build.0 = Release|Any CPU {88B831EC-0DFE-40D7-9449-C4BDAE5B5512}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {88B831EC-0DFE-40D7-9449-C4BDAE5B5512}.Debug|Any CPU.Build.0 = Debug|Any CPU {88B831EC-0DFE-40D7-9449-C4BDAE5B5512}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -549,14 +525,6 @@ Global {B15B9803-EB9D-4BA2-9B09-ACAE8F11252D}.Debug|Any CPU.Build.0 = Debug|Any CPU {B15B9803-EB9D-4BA2-9B09-ACAE8F11252D}.Release|Any CPU.ActiveCfg = Release|Any CPU {B15B9803-EB9D-4BA2-9B09-ACAE8F11252D}.Release|Any CPU.Build.0 = Release|Any CPU - {6CBD9972-ABB1-4E15-8FB7-8F377A081490}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6CBD9972-ABB1-4E15-8FB7-8F377A081490}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6CBD9972-ABB1-4E15-8FB7-8F377A081490}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6CBD9972-ABB1-4E15-8FB7-8F377A081490}.Release|Any CPU.Build.0 = Release|Any CPU - {4A9EFAB3-B798-4323-86C0-39D4C2C67C86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4A9EFAB3-B798-4323-86C0-39D4C2C67C86}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4A9EFAB3-B798-4323-86C0-39D4C2C67C86}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4A9EFAB3-B798-4323-86C0-39D4C2C67C86}.Release|Any CPU.Build.0 = Release|Any CPU {7C3851B7-151E-4DB4-8DC8-DED438D2A998}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7C3851B7-151E-4DB4-8DC8-DED438D2A998}.Release|Any CPU.ActiveCfg = Release|Any CPU {D4F5F69C-9A9F-425C-8DBA-B8053AE506B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -778,7 +746,6 @@ Global {5169916E-092C-431A-8577-50F2713C10CB} = {A820C4C2-1472-46ED-BA95-47B588B1D7AF} {14726095-DA28-43A6-A9A9-F16C605932E1} = {7311E32F-C1B0-41C9-B5F1-DE9EBB6ABB55} {2F591414-63E0-4CD8-AA1E-11132CC20EA9} = {14726095-DA28-43A6-A9A9-F16C605932E1} - {602F852F-77EE-4335-BA45-170C32440575} = {584C62C0-2AE6-4DD6-9BCF-8FF28B7122CE} {20C8482D-1525-47B0-B78B-09632892E8E4} = {7311E32F-C1B0-41C9-B5F1-DE9EBB6ABB55} {7197E4CE-120D-4601-AA8B-F65B8DB2E883} = {20C8482D-1525-47B0-B78B-09632892E8E4} {DD1FF81B-107E-4874-BD37-6E84EAD78EDD} = {20C8482D-1525-47B0-B78B-09632892E8E4} @@ -788,12 +755,10 @@ Global {25A21016-7DF7-4884-9241-AC21D7D35ABE} = {20C8482D-1525-47B0-B78B-09632892E8E4} {3C1C5EBB-A1C4-4B27-A3B2-C99DF646273E} = {584C62C0-2AE6-4DD6-9BCF-8FF28B7122CE} {65743F60-F511-41E1-959B-D29FA3DB404D} = {A4361674-5AB7-442D-8DA7-7187C9BCA38F} - {86A0DCDE-225B-4140-8195-A96F744573F0} = {20C8482D-1525-47B0-B78B-09632892E8E4} {34929B8F-4ED5-499C-A3AC-7ABE0F2F8FFE} = {D28298B7-63A2-4751-BEB9-C3C30F2E7107} {34A864A3-C25C-4DFA-BCE8-173F72B572A3} = {34929B8F-4ED5-499C-A3AC-7ABE0F2F8FFE} {5104F8FE-CF32-4B6A-93FB-B6A651FB9444} = {584C62C0-2AE6-4DD6-9BCF-8FF28B7122CE} {2E99F025-BDC0-430E-AD2A-C81141AC2BCA} = {A4361674-5AB7-442D-8DA7-7187C9BCA38F} - {4831DD42-C73B-47DE-B5F6-9701F9773AD0} = {0407911F-89FC-4138-BD4D-D4CFCFBB5DC1} {88B831EC-0DFE-40D7-9449-C4BDAE5B5512} = {20C8482D-1525-47B0-B78B-09632892E8E4} {FC77C6B6-EAB3-4CC0-8BB0-535BC4CB2C5B} = {20C8482D-1525-47B0-B78B-09632892E8E4} {FA224C96-29E2-45F8-9CB9-B61636664F06} = {20C8482D-1525-47B0-B78B-09632892E8E4} @@ -817,9 +782,6 @@ Global {329C3A29-B023-478C-9D73-91621B101F81} = {F031DBDA-5D3F-4CE6-B133-09CE7E212584} {4B368840-DA86-48FA-969D-A086F016BB7A} = {14726095-DA28-43A6-A9A9-F16C605932E1} {B15B9803-EB9D-4BA2-9B09-ACAE8F11252D} = {584C62C0-2AE6-4DD6-9BCF-8FF28B7122CE} - {6CBD9972-ABB1-4E15-8FB7-8F377A081490} = {20C8482D-1525-47B0-B78B-09632892E8E4} - {A6E20C85-DEC2-4540-83FA-84636CAEE734} = {7311E32F-C1B0-41C9-B5F1-DE9EBB6ABB55} - {4A9EFAB3-B798-4323-86C0-39D4C2C67C86} = {A6E20C85-DEC2-4540-83FA-84636CAEE734} {7C3851B7-151E-4DB4-8DC8-DED438D2A998} = {C5410077-1E20-4DC2-8AB2-AB40CA80C4AF} {D4F5F69C-9A9F-425C-8DBA-B8053AE506B5} = {A4361674-5AB7-442D-8DA7-7187C9BCA38F} {E6C9D6ED-2405-45C6-898A-EE7CE9D7D5B2} = {A4361674-5AB7-442D-8DA7-7187C9BCA38F} diff --git a/samples/MicroServices/NBB.Contracts/NBB.Contracts.Application.Commands/NBB.Contracts.Application.Commands.csproj b/samples/MicroServices/NBB.Contracts/NBB.Contracts.Application.Commands/NBB.Contracts.Application.Commands.csproj index efb52a67..aef22f22 100644 --- a/samples/MicroServices/NBB.Contracts/NBB.Contracts.Application.Commands/NBB.Contracts.Application.Commands.csproj +++ b/samples/MicroServices/NBB.Contracts/NBB.Contracts.Application.Commands/NBB.Contracts.Application.Commands.csproj @@ -21,7 +21,6 @@ - diff --git a/samples/MicroServices/NBB.Contracts/NBB.Contracts.PublishedLanguage/NBB.Contracts.PublishedLanguage.csproj b/samples/MicroServices/NBB.Contracts/NBB.Contracts.PublishedLanguage/NBB.Contracts.PublishedLanguage.csproj index 4a81557c..518a72c6 100644 --- a/samples/MicroServices/NBB.Contracts/NBB.Contracts.PublishedLanguage/NBB.Contracts.PublishedLanguage.csproj +++ b/samples/MicroServices/NBB.Contracts/NBB.Contracts.PublishedLanguage/NBB.Contracts.PublishedLanguage.csproj @@ -13,7 +13,6 @@ - diff --git a/samples/MicroServices/NBB.Contracts/NBB.Contracts.Worker/NBB.Contracts.Worker.csproj b/samples/MicroServices/NBB.Contracts/NBB.Contracts.Worker/NBB.Contracts.Worker.csproj index 317e70a9..e3f32f9b 100644 --- a/samples/MicroServices/NBB.Contracts/NBB.Contracts.Worker/NBB.Contracts.Worker.csproj +++ b/samples/MicroServices/NBB.Contracts/NBB.Contracts.Worker/NBB.Contracts.Worker.csproj @@ -39,7 +39,6 @@ - diff --git a/samples/MicroServices/NBB.Contracts/NBB.Contracts.Worker/Program.cs b/samples/MicroServices/NBB.Contracts/NBB.Contracts.Worker/Program.cs index 7e6697c4..5d809768 100644 --- a/samples/MicroServices/NBB.Contracts/NBB.Contracts.Worker/Program.cs +++ b/samples/MicroServices/NBB.Contracts/NBB.Contracts.Worker/Program.cs @@ -14,7 +14,6 @@ using NBB.Messaging.Host.Builder; using NBB.Messaging.Host.MessagingPipeline; using NBB.Messaging.Nats; -using NBB.Resiliency; using Serilog; using Serilog.Events; using System.IO; @@ -76,8 +75,6 @@ public static async Task Main(string[] _args) .WithNewtownsoftJsonEventStoreSeserializer(new[] { new SingleValueObjectConverter() }) .WithAdoNetEventRepository(); - services.AddResiliency(); - services.AddMessagingHost() .AddSubscriberServices(config => config.FromMediatRHandledCommands().AddAllClasses()) diff --git a/samples/MicroServices/NBB.Invoices/NBB.Invoices.Application.Commands/NBB.Invoices.Application.Commands.csproj b/samples/MicroServices/NBB.Invoices/NBB.Invoices.Application.Commands/NBB.Invoices.Application.Commands.csproj index 21b21fc7..e6f01776 100644 --- a/samples/MicroServices/NBB.Invoices/NBB.Invoices.Application.Commands/NBB.Invoices.Application.Commands.csproj +++ b/samples/MicroServices/NBB.Invoices/NBB.Invoices.Application.Commands/NBB.Invoices.Application.Commands.csproj @@ -21,7 +21,6 @@ - diff --git a/samples/MicroServices/NBB.Invoices/NBB.Invoices.PublishedLanguage/NBB.Invoices.PublishedLanguage.csproj b/samples/MicroServices/NBB.Invoices/NBB.Invoices.PublishedLanguage/NBB.Invoices.PublishedLanguage.csproj index 4a81557c..518a72c6 100644 --- a/samples/MicroServices/NBB.Invoices/NBB.Invoices.PublishedLanguage/NBB.Invoices.PublishedLanguage.csproj +++ b/samples/MicroServices/NBB.Invoices/NBB.Invoices.PublishedLanguage/NBB.Invoices.PublishedLanguage.csproj @@ -13,7 +13,6 @@ - diff --git a/samples/MicroServices/NBB.Invoices/NBB.Invoices.Worker/Program.cs b/samples/MicroServices/NBB.Invoices/NBB.Invoices.Worker/Program.cs index a97d33d7..365d33a6 100644 --- a/samples/MicroServices/NBB.Invoices/NBB.Invoices.Worker/Program.cs +++ b/samples/MicroServices/NBB.Invoices/NBB.Invoices.Worker/Program.cs @@ -17,7 +17,6 @@ using NBB.Messaging.Host.Builder; using NBB.Messaging.Host.MessagingPipeline; using NBB.Messaging.Nats; -using NBB.Resiliency; using Serilog; using Serilog.Events; using Serilog.Sinks.MSSqlServer; @@ -73,8 +72,6 @@ public static async Task Main(string[] _args) .WithNewtownsoftJsonEventStoreSeserializer(new[] {new SingleValueObjectConverter()}) .WithAdoNetEventRepository(); - services.AddResiliency(); - services.AddMessagingHost() .AddSubscriberServices(config => config .FromMediatRHandledCommands().AddAllClasses() diff --git a/samples/MicroServices/NBB.Payments/NBB.Payments.Application.Commands/NBB.Payments.Application.Commands.csproj b/samples/MicroServices/NBB.Payments/NBB.Payments.Application.Commands/NBB.Payments.Application.Commands.csproj index 7299dba3..317db643 100644 --- a/samples/MicroServices/NBB.Payments/NBB.Payments.Application.Commands/NBB.Payments.Application.Commands.csproj +++ b/samples/MicroServices/NBB.Payments/NBB.Payments.Application.Commands/NBB.Payments.Application.Commands.csproj @@ -21,7 +21,6 @@ - diff --git a/samples/MicroServices/NBB.Payments/NBB.Payments.PublishedLanguage/NBB.Payments.PublishedLanguage.csproj b/samples/MicroServices/NBB.Payments/NBB.Payments.PublishedLanguage/NBB.Payments.PublishedLanguage.csproj index bdc8e369..9db83f25 100644 --- a/samples/MicroServices/NBB.Payments/NBB.Payments.PublishedLanguage/NBB.Payments.PublishedLanguage.csproj +++ b/samples/MicroServices/NBB.Payments/NBB.Payments.PublishedLanguage/NBB.Payments.PublishedLanguage.csproj @@ -17,7 +17,6 @@ - diff --git a/samples/MicroServices/NBB.Payments/NBB.Payments.Worker/Program.cs b/samples/MicroServices/NBB.Payments/NBB.Payments.Worker/Program.cs index 4f00453a..dcfcd68a 100644 --- a/samples/MicroServices/NBB.Payments/NBB.Payments.Worker/Program.cs +++ b/samples/MicroServices/NBB.Payments/NBB.Payments.Worker/Program.cs @@ -17,7 +17,6 @@ using NBB.Messaging.Nats; using NBB.Payments.Application.CommandHandlers; using NBB.Payments.Data; -using NBB.Resiliency; using Serilog; using Serilog.Events; using Serilog.Sinks.MSSqlServer; @@ -75,8 +74,6 @@ public static async Task Main(string[] _args) .WithNewtownsoftJsonEventStoreSeserializer(new[] {new SingleValueObjectConverter()}) .WithAdoNetEventRepository(); - services.AddResiliency(); - services.AddMessagingHost() .AddSubscriberServices(config => config .FromMediatRHandledCommands().AddAllClasses() diff --git a/samples/Monolith/NBB.Mono/Startup.cs b/samples/Monolith/NBB.Mono/Startup.cs index b729810d..a4a6b3cc 100644 --- a/samples/Monolith/NBB.Mono/Startup.cs +++ b/samples/Monolith/NBB.Mono/Startup.cs @@ -21,7 +21,6 @@ using NBB.Core.DependencyInjection; using NBB.Domain; using NBB.Messaging.Host; -using NBB.Resiliency; using Microsoft.Extensions.Hosting; using NBB.Messaging.Host.MessagingPipeline; using NBB.Messaging.Host.Builder; @@ -60,8 +59,6 @@ public void ConfigureServices(IServiceCollection services) .WithNewtownsoftJsonEventStoreSeserializer(new[] { new SingleValueObjectConverter() }) .WithAdoNetEventRepository(); - services.AddResiliency(); - services.AddMessagingHost() .AddSubscriberServices(config => config .FromMediatRHandledCommands().AddAllClasses() diff --git a/samples/Orchestration/ProcessManagerSample/MessageMiddlewares/SubscriberLoggingMiddleware.cs b/samples/Orchestration/ProcessManagerSample/MessageMiddlewares/SubscriberLoggingMiddleware.cs index 31d228a6..9a1b0545 100644 --- a/samples/Orchestration/ProcessManagerSample/MessageMiddlewares/SubscriberLoggingMiddleware.cs +++ b/samples/Orchestration/ProcessManagerSample/MessageMiddlewares/SubscriberLoggingMiddleware.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using Microsoft.Extensions.Logging; using NBB.Core.Pipeline; -using NBB.Messaging.DataContracts; +using NBB.Messaging.Abstractions; namespace ProcessManagerSample.MessageMiddlewares { diff --git a/samples/Orchestration/ProcessManagerSample/OrderProcessManager.cs b/samples/Orchestration/ProcessManagerSample/OrderProcessManager.cs index fdd5190d..6d04b96b 100644 --- a/samples/Orchestration/ProcessManagerSample/OrderProcessManager.cs +++ b/samples/Orchestration/ProcessManagerSample/OrderProcessManager.cs @@ -31,12 +31,7 @@ public OrderProcessManager(IMapper mapper) .Then(OrderCreatedHandler); When() - .SetState((received, state) => - { - var newState = state.Data; - newState.OrderId = Guid.NewGuid(); - return newState; - }) + .SetState((received, state) => state.Data with {OrderId = Guid.NewGuid()}) .Then((orderCreated, data) => { var q1 = Mediator.SendQuery(new GetClientQuery()); diff --git a/samples/Orchestration/ProcessManagerSample/OrderProcessManagerData.cs b/samples/Orchestration/ProcessManagerSample/OrderProcessManagerData.cs index 5f835e91..8f73d7f9 100644 --- a/samples/Orchestration/ProcessManagerSample/OrderProcessManagerData.cs +++ b/samples/Orchestration/ProcessManagerSample/OrderProcessManagerData.cs @@ -2,9 +2,9 @@ namespace ProcessManagerSample { - public struct OrderProcessManagerData + public record OrderProcessManagerData { - public Guid OrderId { get; set; } - public bool IsPaid { get; set; } + public Guid OrderId { get; init; } + public bool IsPaid { get; init; } } } \ No newline at end of file diff --git a/samples/Orchestration/ProcessManagerSample/ProcessManagerSample.csproj b/samples/Orchestration/ProcessManagerSample/ProcessManagerSample.csproj index 6288e7ff..e3f186bf 100644 --- a/samples/Orchestration/ProcessManagerSample/ProcessManagerSample.csproj +++ b/samples/Orchestration/ProcessManagerSample/ProcessManagerSample.csproj @@ -28,7 +28,6 @@ - diff --git a/samples/Orchestration/ProcessManagerSample/Program.cs b/samples/Orchestration/ProcessManagerSample/Program.cs index 91327f00..250678b9 100644 --- a/samples/Orchestration/ProcessManagerSample/Program.cs +++ b/samples/Orchestration/ProcessManagerSample/Program.cs @@ -32,7 +32,7 @@ static async Task Main(string[] args) Console.ReadKey(); - var orderId = Guid.Empty; + var orderId = Guid.NewGuid(); var pub = host.Services.GetRequiredService(); await pub.PublishAsync(new OrderCreated(orderId, 100, 0,0)); Console.ReadKey(); diff --git a/samples/Orchestration/ProcessManagerSample/Startup.cs b/samples/Orchestration/ProcessManagerSample/Startup.cs index 15fb015e..8f6a7d30 100644 --- a/samples/Orchestration/ProcessManagerSample/Startup.cs +++ b/samples/Orchestration/ProcessManagerSample/Startup.cs @@ -3,7 +3,6 @@ using MediatR.Pipeline; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using NBB.Core.Abstractions; using NBB.EventStore; using NBB.EventStore.AdoNet; using NBB.Messaging.Host; @@ -11,7 +10,6 @@ using NBB.Messaging.Host.MessagingPipeline; using NBB.Messaging.InProcessMessaging.Extensions; using NBB.ProcessManager.Runtime; -using NBB.Resiliency; using ProcessManagerSample.MessageMiddlewares; using ProcessManagerSample.Queries; using System.Reflection; @@ -36,7 +34,6 @@ public static void ConfigureServicesDelegate(HostBuilderContext context, IServic .WithNewtownsoftJsonEventStoreSeserializer() .WithAdoNetEventRepository(); - services.AddResiliency(); services.AddMessagingHost() .AddSubscriberServices(config => config .FromMediatRHandledCommands().AddAllClasses() diff --git a/src/Application/NBB.Application.MediatR/NBB.Application.MediatR.csproj b/src/Application/NBB.Application.MediatR/NBB.Application.MediatR.csproj index 7766f065..d78de3e3 100644 --- a/src/Application/NBB.Application.MediatR/NBB.Application.MediatR.csproj +++ b/src/Application/NBB.Application.MediatR/NBB.Application.MediatR.csproj @@ -22,7 +22,6 @@ - diff --git a/src/Core/NBB.Core.Abstractions/SetOnce.cs b/src/Core/NBB.Core.Abstractions/SetOnce.cs deleted file mode 100644 index 4f975315..00000000 --- a/src/Core/NBB.Core.Abstractions/SetOnce.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace NBB.Core.Abstractions -{ - public sealed class SetOnce - { - private T _value; - private string _name; - - public SetOnce(string name = null) - { - _name = name; - } - - public T Value - { - get => _value; - set - { - if (!EqualityComparer.Default.Equals(this._value, default(T))) - throw new InvalidOperationException($"{_name ?? nameof(Value)} is already set"); - - this._value = value; - } - } - - public static implicit operator T(SetOnce value) { return value.Value; } - } - -} diff --git a/src/EventStore/NBB.EventStore.Host/EventStoreHostBuilder.cs b/src/EventStore/NBB.EventStore.Host/EventStoreHostBuilder.cs deleted file mode 100644 index a87f5b01..00000000 --- a/src/EventStore/NBB.EventStore.Host/EventStoreHostBuilder.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using NBB.Core.Abstractions; -using NBB.Core.Pipeline; -using System; - -namespace NBB.EventStore.Host -{ - public class EventStoreHostBuilder - { - public IServiceCollection ServiceCollection { get; } - - public EventStoreHostBuilder(IServiceCollection serviceCollection) - { - ServiceCollection = serviceCollection; - AddSubscriberService(); - } - - public EventStoreHostBuilder UsePipeline(Action> configurePipeline) - { - ServiceCollection.AddScoped(serviceProvider => - { - var pipelineBuilder = new PipelineBuilder(serviceProvider); - - configurePipeline(pipelineBuilder); - - return pipelineBuilder.Pipeline; - }); - - return this; - } - - private EventStoreHostBuilder AddSubscriberService() - { - ServiceCollection.AddSingleton(); - - return this; - } - } -} diff --git a/src/EventStore/NBB.EventStore.Host/EventStoreSubscriberService.cs b/src/EventStore/NBB.EventStore.Host/EventStoreSubscriberService.cs deleted file mode 100644 index 9d85acbf..00000000 --- a/src/EventStore/NBB.EventStore.Host/EventStoreSubscriberService.cs +++ /dev/null @@ -1,47 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using NBB.Core.Abstractions; -using NBB.Core.Pipeline; -using NBB.EventStore.Abstractions; -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace NBB.EventStore.Host -{ - public class EventStoreSubscriberService : BackgroundService - { - private readonly IEventStoreSubscriber _eventStoreSubscriber; - private readonly IServiceProvider _serviceProvider; - private readonly ILogger _logger; - - public EventStoreSubscriberService(IEventStoreSubscriber eventStoreSubscriber, IServiceProvider serviceProvider, - ILogger logger) - { - _eventStoreSubscriber = eventStoreSubscriber; - _serviceProvider = serviceProvider; - _logger = logger; - } - - protected override async Task ExecuteAsync(CancellationToken cancellationToken = default) - { - _logger.LogInformation("EventStoreSubscriberService is starting"); - - await _eventStoreSubscriber.SubscribeToAllAsync(@event => Handle(@event, cancellationToken), cancellationToken); - - _logger.LogInformation("EventStoreSubscriberService is stopping"); - } - - - private async Task Handle(object @event, CancellationToken cancellationToken) - { - using (var scope = _serviceProvider.CreateScope()) - { - var pipeline = scope.ServiceProvider.GetService>(); - - await pipeline(@event, cancellationToken); - } - } - } -} diff --git a/src/EventStore/NBB.EventStore.Host/NBB.EventStore.Host.csproj b/src/EventStore/NBB.EventStore.Host/NBB.EventStore.Host.csproj deleted file mode 100644 index c99fed80..00000000 --- a/src/EventStore/NBB.EventStore.Host/NBB.EventStore.Host.csproj +++ /dev/null @@ -1,22 +0,0 @@ - - - - net5.0 - Event store subscribers host - - - - - - - - - - - - - - - - - diff --git a/src/EventStore/NBB.EventStore.Host/Pipeline/DefaultResiliencyMiddleware.cs b/src/EventStore/NBB.EventStore.Host/Pipeline/DefaultResiliencyMiddleware.cs deleted file mode 100644 index 76738083..00000000 --- a/src/EventStore/NBB.EventStore.Host/Pipeline/DefaultResiliencyMiddleware.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Microsoft.Extensions.Logging; -using NBB.Core.Abstractions; -using NBB.Core.Pipeline; -using NBB.Resiliency; -using Polly; -using System; -using System.Runtime.ExceptionServices; -using System.Threading; -using System.Threading.Tasks; - - -namespace NBB.EventStore.Host.Pipeline -{ - public class DefaultResiliencyMiddleware : IPipelineMiddleware - { - private readonly IResiliencyPolicyProvider _resiliencyPolicyProvider; - private readonly ILogger _logger; - - public DefaultResiliencyMiddleware(IResiliencyPolicyProvider resiliencyPolicyProvider, ILogger logger) - { - _resiliencyPolicyProvider = resiliencyPolicyProvider; - _logger = logger; - } - - public async Task Invoke(object @event, CancellationToken cancellationToken, Func next) - { - var outOfOrderPolicy = _resiliencyPolicyProvider.GetOutOfOrderPolicy(retryCount => _logger.LogWarning( - "Event of type {EventType} could not be processed due to OutOfOrderMessageException. Retry count is {RetryCount}.", - @event.GetType().GetPrettyName(), retryCount)); - - var concurencyException = _resiliencyPolicyProvider.GetConcurencyExceptionPolicy(ex => _logger.LogWarning( - "Event of type {EventType} could not be processed due to concurency exception. The system will automatically retry it.", - @event.GetType().GetPrettyName())); - - var policies = Policy.WrapAsync(outOfOrderPolicy, concurencyException); - - var result = await policies.ExecuteAndCaptureAsync(async (_) => - { - await next(); - }, cancellationToken); - - if (result.Outcome == OutcomeType.Failure) - { - ExceptionDispatchInfo.Capture(result.FinalException).Throw(); - } - } - } -} diff --git a/src/EventStore/NBB.EventStore.Host/Pipeline/EventPipelineExtensions.cs b/src/EventStore/NBB.EventStore.Host/Pipeline/EventPipelineExtensions.cs deleted file mode 100644 index 22cdcc27..00000000 --- a/src/EventStore/NBB.EventStore.Host/Pipeline/EventPipelineExtensions.cs +++ /dev/null @@ -1,20 +0,0 @@ -using NBB.Core.Abstractions; -using NBB.Core.Pipeline; - -namespace NBB.EventStore.Host.Pipeline -{ - public static class EventPipelineExtensions - { - public static IPipelineBuilder UseMiddleware(this IPipelineBuilder pipelineBuilder) where TMiddleware : IPipelineMiddleware - => pipelineBuilder.UseMiddleware(); - - public static IPipelineBuilder UseExceptionHandlingMiddleware(this IPipelineBuilder pipelineBuilder) - => UseMiddleware(pipelineBuilder); - - public static IPipelineBuilder UseMediatRMiddleware(this IPipelineBuilder pipelineBilder) - => UseMiddleware(pipelineBilder); - - public static IPipelineBuilder UseDefaultResiliencyMiddleware(this IPipelineBuilder pipelineBuilder) - => UseMiddleware(pipelineBuilder); - } -} diff --git a/src/EventStore/NBB.EventStore.Host/Pipeline/ExceptionHandlingMiddleware.cs b/src/EventStore/NBB.EventStore.Host/Pipeline/ExceptionHandlingMiddleware.cs deleted file mode 100644 index 7548665c..00000000 --- a/src/EventStore/NBB.EventStore.Host/Pipeline/ExceptionHandlingMiddleware.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Microsoft.Extensions.Logging; -using NBB.Core.Abstractions; -using NBB.Core.Pipeline; -using System; -using System.Diagnostics; -using System.Threading; -using System.Threading.Tasks; - -namespace NBB.EventStore.Host.Pipeline -{ - public class ExceptionHandlingMiddleware : IPipelineMiddleware - { - private readonly ILogger _logger; - - public ExceptionHandlingMiddleware(ILogger logger) - { - _logger = logger; - } - - public async Task Invoke(object @event, CancellationToken cancellationToken, Func next) - { - var stopWatch = new Stopwatch(); - stopWatch.Start(); - - try - { - await next(); - - _logger.LogInformation( - "Event of type {EventType} processed in {ElapsedMilliseconds} ms.", - @event.GetType().GetPrettyName(), - stopWatch.ElapsedMilliseconds); - } - catch (Exception ex) - { - _logger.LogError( - "Event of type {EventType} could not be process due to the following exception {Exception}.", - @event.GetType().GetPrettyName(), ex); - } - finally - { - stopWatch.Stop(); - } - } - } -} diff --git a/src/EventStore/NBB.EventStore.Host/Pipeline/MediatRMiddleware.cs b/src/EventStore/NBB.EventStore.Host/Pipeline/MediatRMiddleware.cs deleted file mode 100644 index c4b5c51f..00000000 --- a/src/EventStore/NBB.EventStore.Host/Pipeline/MediatRMiddleware.cs +++ /dev/null @@ -1,29 +0,0 @@ -using MediatR; -using NBB.Core.Abstractions; -using NBB.Core.Pipeline; -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace NBB.EventStore.Host.Pipeline -{ - public class MediatRMiddleware : IPipelineMiddleware - { - private readonly IMediator _mediator; - - public MediatRMiddleware(IMediator mediator) - { - _mediator = mediator; - } - - public async Task Invoke(object @event, CancellationToken cancellationToken, Func next) - { - if (@event is INotification notification) - { - await _mediator.Publish(notification, cancellationToken); - } - - await next(); - } - } -} diff --git a/src/EventStore/NBB.EventStore.Host/ServiceCollectionExtensions.cs b/src/EventStore/NBB.EventStore.Host/ServiceCollectionExtensions.cs deleted file mode 100644 index 8b9529c8..00000000 --- a/src/EventStore/NBB.EventStore.Host/ServiceCollectionExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; - -namespace NBB.EventStore.Host -{ - public static class ServiceCollectionExtensions - { - public static EventStoreHostBuilder AddEventStoreHost(this IServiceCollection serviceCollection) - { - return new EventStoreHostBuilder(serviceCollection); - } - } -} diff --git a/src/EventStore/NBB.GetEventStore/DependencyInjectionExtensions.cs b/src/EventStore/NBB.GetEventStore/DependencyInjectionExtensions.cs deleted file mode 100644 index cea46977..00000000 --- a/src/EventStore/NBB.GetEventStore/DependencyInjectionExtensions.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using NBB.EventStore.Abstractions; -using NBB.GetEventStore.Internal; - -namespace NBB.GetEventStore -{ - public static class DependencyInjectionExtensions - { - public static void AddGetEventStore(this IServiceCollection services) - { - services.AddScoped(); - services.AddScoped(); - services.AddSingleton(); - services.AddTransient(); - - } - } -} diff --git a/src/EventStore/NBB.GetEventStore/GetEventStoreClient.cs b/src/EventStore/NBB.GetEventStore/GetEventStoreClient.cs deleted file mode 100644 index 455ee53e..00000000 --- a/src/EventStore/NBB.GetEventStore/GetEventStoreClient.cs +++ /dev/null @@ -1,100 +0,0 @@ -using EventStore.ClientAPI; -using Microsoft.Extensions.Logging; -using NBB.EventStore.Abstractions; -using NBB.GetEventStore.Internal; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Net; -using System.Threading; -using System.Threading.Tasks; -using CorrelationManager = NBB.Correlation.CorrelationManager; - -namespace NBB.GetEventStore -{ - public class GetEventStoreClient : IEventStore - { - private readonly ISerDes _serDes; - private readonly ILogger _logger; - - public GetEventStoreClient(ISerDes serDes, ILogger logger) - { - _serDes = serDes; - _logger = logger; - } - - public async Task AppendEventsToStreamAsync(string stream, IEnumerable events, int? expectedVersion, CancellationToken cancellationToken = default) - { - var stopWatch = new Stopwatch(); - stopWatch.Start(); - - var gregsEvents = new List(); - foreach (var e in events) - { - var metadata = _serDes.Serialize(new EventMetadata(e.GetType(), CorrelationManager.GetCorrelationId())); - var data = _serDes.Serialize(e); - var ge = new EventData(Guid.NewGuid(), GetFullTypeName(e.GetType()), true, data, metadata); - gregsEvents.Add(ge); - } - - using (var connection = await GetConnectionAsync()) - { - await connection.AppendToStreamAsync(stream, expectedVersion ?? ExpectedVersion.Any, gregsEvents.ToArray()); - } - - stopWatch.Stop(); - _logger.LogDebug("GetEventStoreClient.AppendEventsToStreamAsync for {Stream} took {ElapsedMilliseconds} ms", stream, stopWatch.ElapsedMilliseconds); - } - - public async Task> GetEventsFromStreamAsync(string stream, int? startFromVersion, CancellationToken cancellationToken = default) - { - var stopWatch = new Stopwatch(); - stopWatch.Start(); - - var result = new List(); - var gregsEvents = new List(); - - using (var connection = await GetConnectionAsync()) - { - StreamEventsSlice currentSlice; - long nextSliceStart = StreamPosition.Start; - do - { - currentSlice = await connection.ReadStreamEventsForwardAsync(stream, nextSliceStart, 200, false); - - nextSliceStart = currentSlice.NextEventNumber; - - gregsEvents.AddRange(currentSlice.Events); - } while (!currentSlice.IsEndOfStream); - } - - foreach (var resolvedEvent in gregsEvents) - { - var metadata = _serDes.Deserialize(resolvedEvent.Event.Metadata); - var eventType = metadata.GetEventType(); - var @event = _serDes.Deserialize(resolvedEvent.Event.Data, eventType); - result.Add(@event); - } - - stopWatch.Stop(); - _logger.LogDebug("GetEventStoreClient.GetEventsFromStreamAsync for {Stream} took {ElapsedMilliseconds} ms", stream, stopWatch.ElapsedMilliseconds); - - return result; - } - - private async Task GetConnectionAsync() - { - var connection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Loopback, 1113)); - await connection.ConnectAsync(); - - return connection; - - } - - private static string GetFullTypeName(Type type) - { - var result = type.FullName + ", " + type.Assembly.GetName().Name; - return result; - } - } -} diff --git a/src/EventStore/NBB.GetEventStore/GetEventStoreSubscriber.cs b/src/EventStore/NBB.GetEventStore/GetEventStoreSubscriber.cs deleted file mode 100644 index b1040806..00000000 --- a/src/EventStore/NBB.GetEventStore/GetEventStoreSubscriber.cs +++ /dev/null @@ -1,89 +0,0 @@ -using EventStore.ClientAPI; -using Microsoft.Extensions.Logging; -using NBB.Core.Abstractions; -using NBB.EventStore.Abstractions; -using NBB.GetEventStore.Internal; -using System; -using System.Net; -using System.Threading; -using System.Threading.Tasks; - -namespace NBB.GetEventStore -{ - public class GetEventStoreSubscriber : IEventStoreSubscriber - { - private readonly ISerDes _serDes; - private readonly ILogger _logger; - - public GetEventStoreSubscriber(ISerDes serDes, ILogger logger) - { - _serDes = serDes; - _logger = logger; - } - - public async Task SubscribeToAllAsync(Func handler, CancellationToken cancellationToken = default) - { - using (var connection = await GetConnectionAsync()) - { - - //try - //{ - // var settings = PersistentSubscriptionSettings.Create() - // .DoNotResolveLinkTos() - // .StartFromCurrent(); - - - // await connection.CreatePersistentSubscriptionAsync("NBB.Contracts.Domain.ContractAggregate.Contract", "x", - // settings, new UserCredentials("admin", "changeit")); - //} - //catch (Exception ex) - //{ - - //} - - - var sub = await connection.ConnectToPersistentSubscriptionAsync("NBB.Contracts.Domain.ContractAggregate.Contract", "x", (x, re) => - { - - //wtf? - if (!re.Event.IsJson) - { - return Task.CompletedTask; - } - - var metadata = _serDes.Deserialize(re.Event.Metadata); - var eventType = metadata.GetEventType(); - - _logger.LogDebug("GetEventStore subscriber received message of type {EventType}", eventType.FullName); - - var @event = _serDes.Deserialize(re.Event.Data, eventType); - var res = handler(@event); - - return res; - - }, (_,r, exc) => - { - - }, null, 10, true); - - - await cancellationToken.WhenCanceled(); - } - - } - - - private async Task GetConnectionAsync() - { - var settings = ConnectionSettings.Create() - //.UseConsoleLogger() - //.EnableVerboseLogging() - .KeepReconnecting(); - var connection = EventStoreConnection.Create(settings, new IPEndPoint(IPAddress.Loopback, 1113)); - await connection.ConnectAsync(); - - return connection; - - } - } -} diff --git a/src/EventStore/NBB.GetEventStore/Internal/EventMetadata.cs b/src/EventStore/NBB.GetEventStore/Internal/EventMetadata.cs deleted file mode 100644 index 5522cb06..00000000 --- a/src/EventStore/NBB.GetEventStore/Internal/EventMetadata.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using Newtonsoft.Json; - -namespace NBB.GetEventStore.Internal -{ - public class EventMetadata - { - public string EventTypeIdentifier { get; } - public Guid? CorrelationId { get; } - - [JsonConstructor] - public EventMetadata(string eventTypeIdentifier, Guid? correlationId) - { - EventTypeIdentifier = eventTypeIdentifier; - CorrelationId = correlationId; - } - - public EventMetadata(Type eventType, Guid? correlationId) - : this(GetFullTypeName(eventType), correlationId) - { - } - - public Type GetEventType() - { - return Type.GetType(EventTypeIdentifier); - } - - private static string GetFullTypeName(Type type) - { - var result = type.FullName + ", " + type.Assembly.GetName().Name; - return result; - } - } -} diff --git a/src/EventStore/NBB.GetEventStore/Internal/ISerDes.cs b/src/EventStore/NBB.GetEventStore/Internal/ISerDes.cs deleted file mode 100644 index 71fa81b7..00000000 --- a/src/EventStore/NBB.GetEventStore/Internal/ISerDes.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace NBB.GetEventStore.Internal -{ - public interface ISerDes - { - T Deserialize(byte[] data); - object Deserialize(byte[] data, Type type); - - byte[] Serialize(object obj); - } -} diff --git a/src/EventStore/NBB.GetEventStore/Internal/SerDes.cs b/src/EventStore/NBB.GetEventStore/Internal/SerDes.cs deleted file mode 100644 index cb83fda4..00000000 --- a/src/EventStore/NBB.GetEventStore/Internal/SerDes.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using Newtonsoft.Json; - -namespace NBB.GetEventStore.Internal -{ - public class SerDes : ISerDes - { - public T Deserialize(byte[] data) - { - var json = System.Text.Encoding.UTF8.GetString(data); - var obj = JsonConvert.DeserializeObject(json); - return obj; - } - - public object Deserialize(byte[] data, Type type) - { - var json = System.Text.Encoding.UTF8.GetString(data); - var obj = JsonConvert.DeserializeObject(json, type); - return obj; - } - - public byte[] Serialize(object obj) - { - var json = JsonConvert.SerializeObject(obj, new JsonSerializerSettings() - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore - }); - - return System.Text.Encoding.UTF8.GetBytes(json); - } - } -} diff --git a/src/EventStore/NBB.GetEventStore/NBB.GetEventStore.csproj b/src/EventStore/NBB.GetEventStore/NBB.GetEventStore.csproj deleted file mode 100644 index 623f064d..00000000 --- a/src/EventStore/NBB.GetEventStore/NBB.GetEventStore.csproj +++ /dev/null @@ -1,26 +0,0 @@ - - - - SAK - SAK - SAK - SAK - - - - net5.0 - This package contains an IEventStore implementation based on GetEventStore - - - - - - - - - - - - - - diff --git a/src/Messaging/NBB.Messaging.Abstractions/DefaultMessageTypeRegistry.cs b/src/Messaging/NBB.Messaging.Abstractions/DefaultMessageTypeRegistry.cs index 0d967578..d18090a0 100644 --- a/src/Messaging/NBB.Messaging.Abstractions/DefaultMessageTypeRegistry.cs +++ b/src/Messaging/NBB.Messaging.Abstractions/DefaultMessageTypeRegistry.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Reflection; using System.Text; -using NBB.Messaging.DataContracts; using NBB.Core.Abstractions; namespace NBB.Messaging.Abstractions diff --git a/src/Messaging/NBB.Messaging.Abstractions/DefaultTopicRegistry.cs b/src/Messaging/NBB.Messaging.Abstractions/DefaultTopicRegistry.cs index 53744e36..5a6eb253 100644 --- a/src/Messaging/NBB.Messaging.Abstractions/DefaultTopicRegistry.cs +++ b/src/Messaging/NBB.Messaging.Abstractions/DefaultTopicRegistry.cs @@ -2,7 +2,6 @@ using System.Linq; using Microsoft.Extensions.Configuration; using NBB.Core.Abstractions; -using NBB.Messaging.DataContracts; namespace NBB.Messaging.Abstractions { diff --git a/src/Messaging/NBB.Messaging.Abstractions/IMessageBusPublisher.cs b/src/Messaging/NBB.Messaging.Abstractions/IMessageBusPublisher.cs index 61c8dfe4..ebf6215c 100644 --- a/src/Messaging/NBB.Messaging.Abstractions/IMessageBusPublisher.cs +++ b/src/Messaging/NBB.Messaging.Abstractions/IMessageBusPublisher.cs @@ -1,12 +1,11 @@ using System; -using System.Threading; -using System.Threading.Tasks; -using NBB.Messaging.DataContracts; - -namespace NBB.Messaging.Abstractions -{ - public interface IMessageBusPublisher - { - Task PublishAsync(T message, CancellationToken cancellationToken = default, Action envelopeCustomizer = null, string topicName = null); - } -} +using System.Threading; +using System.Threading.Tasks; + +namespace NBB.Messaging.Abstractions +{ + public interface IMessageBusPublisher + { + Task PublishAsync(T message, CancellationToken cancellationToken = default, Action envelopeCustomizer = null, string topicName = null); + } +} diff --git a/src/Messaging/NBB.Messaging.Abstractions/IMessageBusSubscriber.cs b/src/Messaging/NBB.Messaging.Abstractions/IMessageBusSubscriber.cs index 0ffc85a9..577b46f5 100644 --- a/src/Messaging/NBB.Messaging.Abstractions/IMessageBusSubscriber.cs +++ b/src/Messaging/NBB.Messaging.Abstractions/IMessageBusSubscriber.cs @@ -1,5 +1,4 @@ -using NBB.Messaging.DataContracts; -using System; +using System; using System.Threading; using System.Threading.Tasks; diff --git a/src/Messaging/NBB.Messaging.Abstractions/IMessageSerDes.cs b/src/Messaging/NBB.Messaging.Abstractions/IMessageSerDes.cs index 71dc19bb..ea98f6f0 100644 --- a/src/Messaging/NBB.Messaging.Abstractions/IMessageSerDes.cs +++ b/src/Messaging/NBB.Messaging.Abstractions/IMessageSerDes.cs @@ -1,11 +1,9 @@ -using NBB.Messaging.DataContracts; - -namespace NBB.Messaging.Abstractions -{ - public interface IMessageSerDes - { - string SerializeMessageEnvelope(MessagingEnvelope envelope, MessageSerDesOptions options = null); - MessagingEnvelope DeserializeMessageEnvelope(string envelopeString, MessageSerDesOptions options = null); - MessagingEnvelope DeserializeMessageEnvelope(string envelopeString, MessageSerDesOptions options = null); - } -} +namespace NBB.Messaging.Abstractions +{ + public interface IMessageSerDes + { + string SerializeMessageEnvelope(MessagingEnvelope envelope, MessageSerDesOptions options = null); + MessagingEnvelope DeserializeMessageEnvelope(string envelopeString, MessageSerDesOptions options = null); + MessagingEnvelope DeserializeMessageEnvelope(string envelopeString, MessageSerDesOptions options = null); + } +} diff --git a/src/Messaging/NBB.Messaging.Abstractions/MessageBusPublisher.cs b/src/Messaging/NBB.Messaging.Abstractions/MessageBusPublisher.cs index d38367ca..a7cc2542 100644 --- a/src/Messaging/NBB.Messaging.Abstractions/MessageBusPublisher.cs +++ b/src/Messaging/NBB.Messaging.Abstractions/MessageBusPublisher.cs @@ -1,6 +1,4 @@ -using Microsoft.Extensions.Logging; -using NBB.Core.Abstractions; -using NBB.Messaging.DataContracts; +using NBB.Core.Abstractions; using System; using System.Collections.Generic; using System.Globalization; diff --git a/src/Messaging/NBB.Messaging.Abstractions/MessageBusSubscriber.cs b/src/Messaging/NBB.Messaging.Abstractions/MessageBusSubscriber.cs index e80e9f4d..6fb70a40 100644 --- a/src/Messaging/NBB.Messaging.Abstractions/MessageBusSubscriber.cs +++ b/src/Messaging/NBB.Messaging.Abstractions/MessageBusSubscriber.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Logging; -using NBB.Messaging.DataContracts; using System; using System.Collections.Generic; using System.Linq; diff --git a/src/Messaging/NBB.Messaging.DataContracts/MessageTypeIdAttribute.cs b/src/Messaging/NBB.Messaging.Abstractions/MessageTypeIdAttribute.cs similarity index 83% rename from src/Messaging/NBB.Messaging.DataContracts/MessageTypeIdAttribute.cs rename to src/Messaging/NBB.Messaging.Abstractions/MessageTypeIdAttribute.cs index 03070323..c279d972 100644 --- a/src/Messaging/NBB.Messaging.DataContracts/MessageTypeIdAttribute.cs +++ b/src/Messaging/NBB.Messaging.Abstractions/MessageTypeIdAttribute.cs @@ -1,6 +1,6 @@ using System; -namespace NBB.Messaging.DataContracts +namespace NBB.Messaging.Abstractions { public class MessageTypeIdAttribute : Attribute { diff --git a/src/Messaging/NBB.Messaging.Abstractions/MessagingContext.cs b/src/Messaging/NBB.Messaging.Abstractions/MessagingContext.cs index 23794090..56fca667 100644 --- a/src/Messaging/NBB.Messaging.Abstractions/MessagingContext.cs +++ b/src/Messaging/NBB.Messaging.Abstractions/MessagingContext.cs @@ -1,6 +1,4 @@ -using NBB.Messaging.DataContracts; - -namespace NBB.Messaging.Abstractions +namespace NBB.Messaging.Abstractions { public class MessagingContext { diff --git a/src/Messaging/NBB.Messaging.DataContracts/MessagingEnvelope.cs b/src/Messaging/NBB.Messaging.Abstractions/MessagingEnvelope.cs similarity index 93% rename from src/Messaging/NBB.Messaging.DataContracts/MessagingEnvelope.cs rename to src/Messaging/NBB.Messaging.Abstractions/MessagingEnvelope.cs index 287c4847..d7b8656f 100644 --- a/src/Messaging/NBB.Messaging.DataContracts/MessagingEnvelope.cs +++ b/src/Messaging/NBB.Messaging.Abstractions/MessagingEnvelope.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace NBB.Messaging.DataContracts +namespace NBB.Messaging.Abstractions { public class MessagingEnvelope { diff --git a/src/Messaging/NBB.Messaging.Abstractions/MessagingEnvelopeExtensions.cs b/src/Messaging/NBB.Messaging.Abstractions/MessagingEnvelopeExtensions.cs index 7bef45bb..273b7a60 100644 --- a/src/Messaging/NBB.Messaging.Abstractions/MessagingEnvelopeExtensions.cs +++ b/src/Messaging/NBB.Messaging.Abstractions/MessagingEnvelopeExtensions.cs @@ -1,5 +1,4 @@ -using NBB.Messaging.DataContracts; -using System; +using System; using System.Collections.Generic; namespace NBB.Messaging.Abstractions diff --git a/src/Messaging/NBB.Messaging.Abstractions/NBB.Messaging.Abstractions.csproj b/src/Messaging/NBB.Messaging.Abstractions/NBB.Messaging.Abstractions.csproj index 170d0de4..fd7a5bff 100644 --- a/src/Messaging/NBB.Messaging.Abstractions/NBB.Messaging.Abstractions.csproj +++ b/src/Messaging/NBB.Messaging.Abstractions/NBB.Messaging.Abstractions.csproj @@ -18,12 +18,13 @@ + + - diff --git a/src/Messaging/NBB.Messaging.Abstractions/NewtonsoftJsonMessageSerDes.cs b/src/Messaging/NBB.Messaging.Abstractions/NewtonsoftJsonMessageSerDes.cs index 7653f55a..2ca17865 100644 --- a/src/Messaging/NBB.Messaging.Abstractions/NewtonsoftJsonMessageSerDes.cs +++ b/src/Messaging/NBB.Messaging.Abstractions/NewtonsoftJsonMessageSerDes.cs @@ -1,5 +1,4 @@ using System; -using NBB.Messaging.DataContracts; using Newtonsoft.Json; using Newtonsoft.Json.Linq; diff --git a/src/Messaging/NBB.Messaging.DataContracts/TopicNameAttribute.cs b/src/Messaging/NBB.Messaging.Abstractions/TopicNameAttribute.cs similarity index 91% rename from src/Messaging/NBB.Messaging.DataContracts/TopicNameAttribute.cs rename to src/Messaging/NBB.Messaging.Abstractions/TopicNameAttribute.cs index a2d9a584..c3ff5952 100644 --- a/src/Messaging/NBB.Messaging.DataContracts/TopicNameAttribute.cs +++ b/src/Messaging/NBB.Messaging.Abstractions/TopicNameAttribute.cs @@ -1,7 +1,7 @@ using System; using Microsoft.Extensions.Configuration; -namespace NBB.Messaging.DataContracts +namespace NBB.Messaging.Abstractions { public class TopicNameAttribute : TopicNameResolverAttribute { diff --git a/src/Messaging/NBB.Messaging.DataContracts/TopicNameResolverAttribute.cs b/src/Messaging/NBB.Messaging.Abstractions/TopicNameResolverAttribute.cs similarity index 86% rename from src/Messaging/NBB.Messaging.DataContracts/TopicNameResolverAttribute.cs rename to src/Messaging/NBB.Messaging.Abstractions/TopicNameResolverAttribute.cs index 61211fd9..cacfb3f9 100644 --- a/src/Messaging/NBB.Messaging.DataContracts/TopicNameResolverAttribute.cs +++ b/src/Messaging/NBB.Messaging.Abstractions/TopicNameResolverAttribute.cs @@ -1,7 +1,7 @@ using System; using Microsoft.Extensions.Configuration; -namespace NBB.Messaging.DataContracts +namespace NBB.Messaging.Abstractions { public abstract class TopicNameResolverAttribute : Attribute { diff --git a/src/Messaging/NBB.Messaging.DataContracts/IMessage.cs b/src/Messaging/NBB.Messaging.DataContracts/IMessage.cs deleted file mode 100644 index f9bd0d16..00000000 --- a/src/Messaging/NBB.Messaging.DataContracts/IMessage.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace NBB.Messaging.DataContracts -{ - public interface IMessage - { - } -} diff --git a/src/Messaging/NBB.Messaging.DataContracts/NBB.Messaging.DataContracts.csproj b/src/Messaging/NBB.Messaging.DataContracts/NBB.Messaging.DataContracts.csproj deleted file mode 100644 index 37caaf2b..00000000 --- a/src/Messaging/NBB.Messaging.DataContracts/NBB.Messaging.DataContracts.csproj +++ /dev/null @@ -1,28 +0,0 @@ - - - - SAK - SAK - SAK - SAK - - - - net5.0 - A few lightweight messaging data contracts. You should reference this package from published language. - - - - - - - - - - - - - - - - diff --git a/src/Messaging/NBB.Messaging.DataContracts/SerializedMessage.cs b/src/Messaging/NBB.Messaging.DataContracts/SerializedMessage.cs deleted file mode 100644 index 177cb8a2..00000000 --- a/src/Messaging/NBB.Messaging.DataContracts/SerializedMessage.cs +++ /dev/null @@ -1,25 +0,0 @@ -using NBB.Core.Abstractions; -using System; - -namespace NBB.Messaging.DataContracts -{ - public abstract class SerializedMessage : ICorrelatable, IKeyProvider - { - public string Body { get; } - public string TypeId { get; } - public Guid? CorrelationId { get; set; } - public string Key { get; } - public Guid MessageId { get; } - public DateTime CreationDate { get; } - - protected SerializedMessage(string body, string typeId, Guid messageId, DateTime creationDate, Guid? correlationId, string key) - { - Body = body; - TypeId = typeId; - MessageId = messageId; - CreationDate = creationDate; - CorrelationId = correlationId; - Key = key; - } - } -} \ No newline at end of file diff --git a/src/Messaging/NBB.Messaging.Host/Builder/MessagingHostBuilder.cs b/src/Messaging/NBB.Messaging.Host/Builder/MessagingHostBuilder.cs index e5a0d13b..2b538888 100644 --- a/src/Messaging/NBB.Messaging.Host/Builder/MessagingHostBuilder.cs +++ b/src/Messaging/NBB.Messaging.Host/Builder/MessagingHostBuilder.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using NBB.Core.Pipeline; -using NBB.Messaging.DataContracts; +using NBB.Messaging.Abstractions; using NBB.Messaging.Host.Builder.TypeSelector; using System; diff --git a/src/Messaging/NBB.Messaging.Host/MessageBusSubscriberService.cs b/src/Messaging/NBB.Messaging.Host/MessageBusSubscriberService.cs index 903e7407..2250aa1f 100644 --- a/src/Messaging/NBB.Messaging.Host/MessageBusSubscriberService.cs +++ b/src/Messaging/NBB.Messaging.Host/MessageBusSubscriberService.cs @@ -2,9 +2,8 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using NBB.Core.Abstractions; -using NBB.Core.Pipeline; +using NBB.Core.Pipeline; using NBB.Messaging.Abstractions; -using NBB.Messaging.DataContracts; using System; using System.Threading; using System.Threading.Tasks; diff --git a/src/Messaging/NBB.Messaging.Host/MessagingContextBusPublisherDecorator.cs b/src/Messaging/NBB.Messaging.Host/MessagingContextBusPublisherDecorator.cs index ab304be9..87dca804 100644 --- a/src/Messaging/NBB.Messaging.Host/MessagingContextBusPublisherDecorator.cs +++ b/src/Messaging/NBB.Messaging.Host/MessagingContextBusPublisherDecorator.cs @@ -1,6 +1,5 @@ using NBB.Correlation; using NBB.Messaging.Abstractions; -using NBB.Messaging.DataContracts; using System; using System.Threading; using System.Threading.Tasks; diff --git a/src/Messaging/NBB.Messaging.Host/MessagingPipeline/CorrelationMiddleware.cs b/src/Messaging/NBB.Messaging.Host/MessagingPipeline/CorrelationMiddleware.cs index 44945e71..c5c3c9be 100644 --- a/src/Messaging/NBB.Messaging.Host/MessagingPipeline/CorrelationMiddleware.cs +++ b/src/Messaging/NBB.Messaging.Host/MessagingPipeline/CorrelationMiddleware.cs @@ -1,7 +1,6 @@ using NBB.Core.Pipeline; using NBB.Correlation; using NBB.Messaging.Abstractions; -using NBB.Messaging.DataContracts; using System; using System.Threading; using System.Threading.Tasks; diff --git a/src/Messaging/NBB.Messaging.Host/MessagingPipeline/DefaultResiliencyMiddleware.cs b/src/Messaging/NBB.Messaging.Host/MessagingPipeline/DefaultResiliencyMiddleware.cs index 83c85f77..07c10d03 100644 --- a/src/Messaging/NBB.Messaging.Host/MessagingPipeline/DefaultResiliencyMiddleware.cs +++ b/src/Messaging/NBB.Messaging.Host/MessagingPipeline/DefaultResiliencyMiddleware.cs @@ -1,8 +1,7 @@ using Microsoft.Extensions.Logging; using NBB.Core.Abstractions; using NBB.Core.Pipeline; -using NBB.Messaging.DataContracts; -using NBB.Resiliency; +using NBB.Messaging.Abstractions; using Polly; using System; using System.Runtime.ExceptionServices; @@ -14,40 +13,54 @@ namespace NBB.Messaging.Host.MessagingPipeline /// /// A pipeline middleware that offers resiliency policies for "out of order" and concurrency exceptions. /// - /// + /// public class DefaultResiliencyMiddleware : IPipelineMiddleware { - private readonly IResiliencyPolicyProvider _resiliencyPolicyProvider; private readonly ILogger _logger; - public DefaultResiliencyMiddleware(IResiliencyPolicyProvider resiliencyPolicyProvider, ILogger logger) + public DefaultResiliencyMiddleware(ILogger logger) { - _resiliencyPolicyProvider = resiliencyPolicyProvider; _logger = logger; } public async Task Invoke(MessagingEnvelope message, CancellationToken cancellationToken, Func next) { - var outOfOrderPolicy = _resiliencyPolicyProvider.GetOutOfOrderPolicy(retryCount => _logger.LogWarning( - "Message of type {MessageType} could not be processed due to OutOfOrderMessageException. Retry count is {RetryCount}.", - message.Payload.GetType().GetPrettyName(), retryCount)); + var outOfOrderPolicy = GetOutOfOrderPolicy(retryCount => _logger.LogWarning( + "Message of type {MessageType} could not be processed due to OutOfOrderMessageException. Retry count is {RetryCount}.", + message.Payload.GetType().GetPrettyName(), retryCount)); - var concurrencyException = _resiliencyPolicyProvider.GetConcurencyExceptionPolicy(ex => + var concurrencyException = GetConcurrencyExceptionPolicy(_ => _logger.LogWarning( "Message of type {MessageType} could not be processed due to concurrency exception. The system will automatically retry it.", message.Payload.GetType().GetPrettyName())); var policies = Policy.WrapAsync(outOfOrderPolicy, concurrencyException); - var result = await policies.ExecuteAndCaptureAsync(async (_) => - { - await next(); - }, cancellationToken); + var result = await policies.ExecuteAndCaptureAsync(async (_) => { await next(); }, cancellationToken); if (result.Outcome == OutcomeType.Failure) { ExceptionDispatchInfo.Capture(result.FinalException).Throw(); } } + + private AsyncPolicy GetOutOfOrderPolicy(Action onRetry) + { + var policy = Policy + .Handle() + .WaitAndRetryAsync(3, i => TimeSpan.FromSeconds(Math.Pow(i, 2)), + (_, _, retryCount, _) => { onRetry(retryCount); }); + + return policy; + } + + private AsyncPolicy GetConcurrencyExceptionPolicy(Action onRetry) + { + var policy = Policy + .Handle() + .RetryForeverAsync(onRetry); + + return policy; + } } -} +} \ No newline at end of file diff --git a/src/Messaging/NBB.Messaging.Host/MessagingPipeline/ExceptionHandlingMiddleware.cs b/src/Messaging/NBB.Messaging.Host/MessagingPipeline/ExceptionHandlingMiddleware.cs index 367d67b5..15976ba8 100644 --- a/src/Messaging/NBB.Messaging.Host/MessagingPipeline/ExceptionHandlingMiddleware.cs +++ b/src/Messaging/NBB.Messaging.Host/MessagingPipeline/ExceptionHandlingMiddleware.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.Logging; using NBB.Core.Abstractions; using NBB.Core.Pipeline; -using NBB.Messaging.DataContracts; +using NBB.Messaging.Abstractions; using System; using System.Diagnostics; using System.Threading; diff --git a/src/Messaging/NBB.Messaging.Host/MessagingPipeline/MediatRMiddleware.cs b/src/Messaging/NBB.Messaging.Host/MessagingPipeline/MediatRMiddleware.cs index c531fd25..513f1418 100644 --- a/src/Messaging/NBB.Messaging.Host/MessagingPipeline/MediatRMiddleware.cs +++ b/src/Messaging/NBB.Messaging.Host/MessagingPipeline/MediatRMiddleware.cs @@ -1,6 +1,6 @@ using MediatR; using NBB.Core.Pipeline; -using NBB.Messaging.DataContracts; +using NBB.Messaging.Abstractions; using System; using System.Threading; using System.Threading.Tasks; diff --git a/src/Messaging/NBB.Messaging.Host/MessagingPipeline/MessagingPipelineExtensions.cs b/src/Messaging/NBB.Messaging.Host/MessagingPipeline/MessagingPipelineExtensions.cs index 996ebfa0..eb747790 100644 --- a/src/Messaging/NBB.Messaging.Host/MessagingPipeline/MessagingPipelineExtensions.cs +++ b/src/Messaging/NBB.Messaging.Host/MessagingPipeline/MessagingPipelineExtensions.cs @@ -2,7 +2,7 @@ using Microsoft.Extensions.DependencyInjection; using NBB.Core.Effects; using NBB.Core.Pipeline; -using NBB.Messaging.DataContracts; +using NBB.Messaging.Abstractions; namespace NBB.Messaging.Host.MessagingPipeline { diff --git a/src/Messaging/NBB.Messaging.Host/MessagingTopicSubscriberService.cs b/src/Messaging/NBB.Messaging.Host/MessagingTopicSubscriberService.cs index 3d989fc9..02566620 100644 --- a/src/Messaging/NBB.Messaging.Host/MessagingTopicSubscriberService.cs +++ b/src/Messaging/NBB.Messaging.Host/MessagingTopicSubscriberService.cs @@ -7,7 +7,6 @@ using NBB.Core.Abstractions; using NBB.Core.Pipeline; using NBB.Messaging.Abstractions; -using NBB.Messaging.DataContracts; namespace NBB.Messaging.Host { diff --git a/src/Messaging/NBB.Messaging.Host/NBB.Messaging.Host.csproj b/src/Messaging/NBB.Messaging.Host/NBB.Messaging.Host.csproj index 44df860a..11ff7761 100644 --- a/src/Messaging/NBB.Messaging.Host/NBB.Messaging.Host.csproj +++ b/src/Messaging/NBB.Messaging.Host/NBB.Messaging.Host.csproj @@ -12,6 +12,7 @@ + @@ -19,7 +20,6 @@ - diff --git a/src/Messaging/NBB.Messaging.MultiTenancy/MultiTenancyMessageBusPublisherDecorator.cs b/src/Messaging/NBB.Messaging.MultiTenancy/MultiTenancyMessageBusPublisherDecorator.cs index 7edbbc5f..aa6efdd4 100644 --- a/src/Messaging/NBB.Messaging.MultiTenancy/MultiTenancyMessageBusPublisherDecorator.cs +++ b/src/Messaging/NBB.Messaging.MultiTenancy/MultiTenancyMessageBusPublisherDecorator.cs @@ -2,7 +2,6 @@ using System.Threading; using System.Threading.Tasks; using NBB.Messaging.Abstractions; -using NBB.Messaging.DataContracts; using NBB.MultiTenancy.Abstractions.Context; namespace NBB.Messaging.MultiTenancy diff --git a/src/Messaging/NBB.Messaging.MultiTenancy/TenantMiddleware.cs b/src/Messaging/NBB.Messaging.MultiTenancy/TenantMiddleware.cs index 0be20e87..28faaa4f 100644 --- a/src/Messaging/NBB.Messaging.MultiTenancy/TenantMiddleware.cs +++ b/src/Messaging/NBB.Messaging.MultiTenancy/TenantMiddleware.cs @@ -1,5 +1,5 @@ using NBB.Core.Pipeline; -using NBB.Messaging.DataContracts; +using NBB.Messaging.Abstractions; using System; using System.Threading; using System.Threading.Tasks; diff --git a/src/Messaging/NBB.Messaging.OpenTracing/Publisher/OpenTracingPublisherDecorator.cs b/src/Messaging/NBB.Messaging.OpenTracing/Publisher/OpenTracingPublisherDecorator.cs index a7d0f2fc..574c42d6 100644 --- a/src/Messaging/NBB.Messaging.OpenTracing/Publisher/OpenTracingPublisherDecorator.cs +++ b/src/Messaging/NBB.Messaging.OpenTracing/Publisher/OpenTracingPublisherDecorator.cs @@ -1,7 +1,6 @@ using NBB.Core.Abstractions; using NBB.Correlation; using NBB.Messaging.Abstractions; -using NBB.Messaging.DataContracts; using OpenTracing; using OpenTracing.Propagation; using OpenTracing.Tag; diff --git a/src/Messaging/NBB.Messaging.OpenTracing/Subscriber/MessagingPipelineExtensions.cs b/src/Messaging/NBB.Messaging.OpenTracing/Subscriber/MessagingPipelineExtensions.cs index 66ec262e..59400a23 100644 --- a/src/Messaging/NBB.Messaging.OpenTracing/Subscriber/MessagingPipelineExtensions.cs +++ b/src/Messaging/NBB.Messaging.OpenTracing/Subscriber/MessagingPipelineExtensions.cs @@ -1,5 +1,5 @@ using NBB.Core.Pipeline; -using NBB.Messaging.DataContracts; +using NBB.Messaging.Abstractions; namespace NBB.Messaging.OpenTracing.Subscriber { diff --git a/src/Messaging/NBB.Messaging.OpenTracing/Subscriber/OpenTracingMiddleware.cs b/src/Messaging/NBB.Messaging.OpenTracing/Subscriber/OpenTracingMiddleware.cs index a103bf4a..4fa28747 100644 --- a/src/Messaging/NBB.Messaging.OpenTracing/Subscriber/OpenTracingMiddleware.cs +++ b/src/Messaging/NBB.Messaging.OpenTracing/Subscriber/OpenTracingMiddleware.cs @@ -2,7 +2,6 @@ using NBB.Core.Pipeline; using NBB.Correlation; using NBB.Messaging.Abstractions; -using NBB.Messaging.DataContracts; using OpenTracing; using OpenTracing.Propagation; using OpenTracing.Tag; diff --git a/src/Orchestration/NBB.ProcessManager.Definition/Builder/AbstractDefinition.cs b/src/Orchestration/NBB.ProcessManager.Definition/Builder/AbstractDefinition.cs index ddb5db6b..92a08ca1 100644 --- a/src/Orchestration/NBB.ProcessManager.Definition/Builder/AbstractDefinition.cs +++ b/src/Orchestration/NBB.ProcessManager.Definition/Builder/AbstractDefinition.cs @@ -6,7 +6,6 @@ namespace NBB.ProcessManager.Definition.Builder { public abstract class AbstractDefinition : IDefinition - where TData : struct { private readonly List> _eventActivities = new List>(); private readonly Dictionary> _eventCorrelations = new Dictionary>(); @@ -73,7 +72,7 @@ SetStateFunc IDefinition.GetSetStateFunc() } ); - return (@event, data) => func?.Invoke(@event, data) ?? data.Data; + return (@event, data) => func == null ? data.Data : func.Invoke(@event, data); } EventPredicate IDefinition.GetStarterPredicate() diff --git a/src/Orchestration/NBB.ProcessManager.Definition/Builder/EventActivitySet.cs b/src/Orchestration/NBB.ProcessManager.Definition/Builder/EventActivitySet.cs index ddc93bdb..35e268a5 100644 --- a/src/Orchestration/NBB.ProcessManager.Definition/Builder/EventActivitySet.cs +++ b/src/Orchestration/NBB.ProcessManager.Definition/Builder/EventActivitySet.cs @@ -5,7 +5,6 @@ namespace NBB.ProcessManager.Definition.Builder { public class EventActivitySet : IEventActivitySet - where TData : struct { public EffectFunc EffectFunc { get; set; } public SetStateFunc SetStateFunc { get; set; } @@ -90,7 +89,6 @@ public void UseForCompletion(EventPredicate predicate = null) } public interface IEventActivitySet - where TData : struct { Type EventType { get; } bool CompletesProcess { get; } diff --git a/src/Orchestration/NBB.ProcessManager.Definition/Builder/EventActivitySetBuilder.cs b/src/Orchestration/NBB.ProcessManager.Definition/Builder/EventActivitySetBuilder.cs index 8e090b34..17b7603e 100644 --- a/src/Orchestration/NBB.ProcessManager.Definition/Builder/EventActivitySetBuilder.cs +++ b/src/Orchestration/NBB.ProcessManager.Definition/Builder/EventActivitySetBuilder.cs @@ -6,7 +6,6 @@ namespace NBB.ProcessManager.Definition.Builder { public class EventActivitySetBuilder - where TData : struct { private readonly EventActivitySet _eventActivitySet; diff --git a/src/Orchestration/NBB.ProcessManager.Definition/Builder/EventCorrelationBuilder.cs b/src/Orchestration/NBB.ProcessManager.Definition/Builder/EventCorrelationBuilder.cs index b739bc6b..c75fb1f4 100644 --- a/src/Orchestration/NBB.ProcessManager.Definition/Builder/EventCorrelationBuilder.cs +++ b/src/Orchestration/NBB.ProcessManager.Definition/Builder/EventCorrelationBuilder.cs @@ -2,8 +2,7 @@ namespace NBB.ProcessManager.Definition.Builder { - public class EventCorrelationBuilder - where TData : struct + public class EventCorrelationBuilder { private Func _correlationFilter; diff --git a/src/Orchestration/NBB.ProcessManager.Definition/Delegates.cs b/src/Orchestration/NBB.ProcessManager.Definition/Delegates.cs index 5fe29ae9..93168f2e 100644 --- a/src/Orchestration/NBB.ProcessManager.Definition/Delegates.cs +++ b/src/Orchestration/NBB.ProcessManager.Definition/Delegates.cs @@ -3,17 +3,16 @@ namespace NBB.ProcessManager.Definition { - public delegate Effect EffectFunc(TEvent @event, InstanceData data) where TData : struct; + public delegate Effect EffectFunc(TEvent @event, InstanceData data); - public delegate TData SetStateFunc(TEvent @event, InstanceData data) where TData : struct; + public delegate TData SetStateFunc(TEvent @event, InstanceData data); - public delegate bool EventPredicate(TEvent @event, InstanceData data) where TData : struct; + public delegate bool EventPredicate(TEvent @event, InstanceData data); public static class EffectFuncs { public static EffectFunc Aggregate(EffectFunc func1, EffectFunc func2, Func, Effect, Effect> accumulator) - where TData : struct { return (@event, data) => { @@ -25,7 +24,6 @@ public static EffectFunc Aggregate(EffectFunc Sequential(EffectFunc func1, EffectFunc func2) - where TData : struct { return Aggregate(func1, func2, (effect1, effect2) => effect1.Then(effect2)); } diff --git a/src/Orchestration/NBB.ProcessManager.Definition/IDefinition.cs b/src/Orchestration/NBB.ProcessManager.Definition/IDefinition.cs index e99447c1..5b7fc5aa 100644 --- a/src/Orchestration/NBB.ProcessManager.Definition/IDefinition.cs +++ b/src/Orchestration/NBB.ProcessManager.Definition/IDefinition.cs @@ -4,7 +4,6 @@ namespace NBB.ProcessManager.Definition { public interface IDefinition : IDefinition - where TData : struct { EffectFunc GetEffectFunc(); SetStateFunc GetSetStateFunc(); diff --git a/src/Orchestration/NBB.ProcessManager.Definition/InstanceData.cs b/src/Orchestration/NBB.ProcessManager.Definition/InstanceData.cs index 59afd511..3af34c65 100644 --- a/src/Orchestration/NBB.ProcessManager.Definition/InstanceData.cs +++ b/src/Orchestration/NBB.ProcessManager.Definition/InstanceData.cs @@ -1,7 +1,6 @@ namespace NBB.ProcessManager.Definition { public struct InstanceData - where TData : struct { public object InstanceId { get; } public TData Data { get; } diff --git a/src/Orchestration/NBB.ProcessManager.Runtime/Instance.cs b/src/Orchestration/NBB.ProcessManager.Runtime/Instance.cs index 87475587..5063e80c 100644 --- a/src/Orchestration/NBB.ProcessManager.Runtime/Instance.cs +++ b/src/Orchestration/NBB.ProcessManager.Runtime/Instance.cs @@ -6,8 +6,8 @@ namespace NBB.ProcessManager.Runtime { - public class Instance - where TData : struct + public class Instance + where TData : new() { private readonly IDefinition _definition; public TData Data { get; private set; } @@ -24,6 +24,7 @@ public class Instance public Instance(IDefinition definition) { _definition = definition; + Data = new TData(); } private void StartProcess(TEvent @event) diff --git a/src/Orchestration/NBB.ProcessManager.Runtime/Persistence/IInstanceDataRepository.cs b/src/Orchestration/NBB.ProcessManager.Runtime/Persistence/IInstanceDataRepository.cs index 2206bbf6..b32b1e4e 100644 --- a/src/Orchestration/NBB.ProcessManager.Runtime/Persistence/IInstanceDataRepository.cs +++ b/src/Orchestration/NBB.ProcessManager.Runtime/Persistence/IInstanceDataRepository.cs @@ -6,10 +6,8 @@ namespace NBB.ProcessManager.Runtime.Persistence { public interface IInstanceDataRepository { - Task Save(Instance instance, CancellationToken cancellationToken = default) - where TData : struct; + Task Save(Instance instance, CancellationToken cancellationToken = default) where TData: new(); - Task> Get(IDefinition definition, object identity, CancellationToken cancellationToken = default) - where TData : struct; + Task> Get(IDefinition definition, object identity, CancellationToken cancellationToken = default) where TData: new(); } } \ No newline at end of file diff --git a/src/Orchestration/NBB.ProcessManager.Runtime/Persistence/InstanceDataRepository.cs b/src/Orchestration/NBB.ProcessManager.Runtime/Persistence/InstanceDataRepository.cs index d96c10b3..b5cd7327 100644 --- a/src/Orchestration/NBB.ProcessManager.Runtime/Persistence/InstanceDataRepository.cs +++ b/src/Orchestration/NBB.ProcessManager.Runtime/Persistence/InstanceDataRepository.cs @@ -20,7 +20,7 @@ public InstanceDataRepository(IEventStore eventStore, IInterpreter interpreter) } public async Task Save(Instance instance, CancellationToken cancellationToken = default) - where TData : struct + where TData: new() { var events = instance.GetUncommittedChanges().ToList(); var effects = instance.GetUncommittedEffects().ToList(); @@ -34,7 +34,7 @@ public async Task Save(Instance instance, CancellationToken cancel } public async Task> Get(IDefinition definition, object identity, CancellationToken cancellationToken = default) - where TData : struct + where TData: new() { var instance = new Instance(definition); var streamId = instance.GetStreamFor(identity); diff --git a/src/Orchestration/NBB.ProcessManager.Runtime/ProcessExecutionCoordinator.cs b/src/Orchestration/NBB.ProcessManager.Runtime/ProcessExecutionCoordinator.cs index 773f2fdc..7c9448f7 100644 --- a/src/Orchestration/NBB.ProcessManager.Runtime/ProcessExecutionCoordinator.cs +++ b/src/Orchestration/NBB.ProcessManager.Runtime/ProcessExecutionCoordinator.cs @@ -21,7 +21,7 @@ public ProcessExecutionCoordinator(IInstanceDataRepository dataRepository, IEnum public async Task Invoke(TEvent @event, CancellationToken cancellationToken = default) where TDefinition : IDefinition - where TData : struct + where TData: new() { var definition = _definitions.OfType().SingleOrDefault(); if (definition == null) diff --git a/src/Orchestration/NBB.ProcessManager.Runtime/ProcessManagerNotificationHandler.cs b/src/Orchestration/NBB.ProcessManager.Runtime/ProcessManagerNotificationHandler.cs index 0f8d039f..b89cdc9c 100644 --- a/src/Orchestration/NBB.ProcessManager.Runtime/ProcessManagerNotificationHandler.cs +++ b/src/Orchestration/NBB.ProcessManager.Runtime/ProcessManagerNotificationHandler.cs @@ -7,7 +7,7 @@ namespace NBB.ProcessManager.Runtime { public class ProcessManagerNotificationHandler : INotificationHandler where TDefinition : IDefinition - where TData : struct + where TData: new() where TEvent : INotification { private readonly ProcessExecutionCoordinator _pec; diff --git a/src/Resiliency/NBB.Resiliency/IResiliencyPolicyProvider.cs b/src/Resiliency/NBB.Resiliency/IResiliencyPolicyProvider.cs deleted file mode 100644 index c9887b84..00000000 --- a/src/Resiliency/NBB.Resiliency/IResiliencyPolicyProvider.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using Polly; - -namespace NBB.Resiliency -{ - public interface IResiliencyPolicyProvider - { - AsyncPolicy GetOutOfOrderPolicy(Action onRetry); - AsyncPolicy GetConcurencyExceptionPolicy(Action onRetry); - } -} diff --git a/src/Resiliency/NBB.Resiliency/NBB.Resiliency.csproj b/src/Resiliency/NBB.Resiliency/NBB.Resiliency.csproj deleted file mode 100644 index 832fef99..00000000 --- a/src/Resiliency/NBB.Resiliency/NBB.Resiliency.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - net5.0 - A resiliency policy library - - - - - - - - - - - - diff --git a/src/Resiliency/NBB.Resiliency/ResiliencyPolicyProvider.cs b/src/Resiliency/NBB.Resiliency/ResiliencyPolicyProvider.cs deleted file mode 100644 index fa49f838..00000000 --- a/src/Resiliency/NBB.Resiliency/ResiliencyPolicyProvider.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using NBB.Core.Abstractions; -using Polly; - -namespace NBB.Resiliency -{ - public class ResiliencyPolicyProvider : IResiliencyPolicyProvider - { - public AsyncPolicy GetOutOfOrderPolicy(Action onRetry) - { - var policy = Policy - .Handle() - .WaitAndRetryAsync(3, i => TimeSpan.FromSeconds(Math.Pow(i, 2)), - (exception, timeSpan, retryCount, context) => - { - onRetry(retryCount); - }); - - return policy; - } - - public AsyncPolicy GetConcurencyExceptionPolicy(Action onRetry) - { - var policy = Policy - .Handle() - .RetryForeverAsync(onRetry); - - return policy; - } - } -} diff --git a/src/Resiliency/NBB.Resiliency/ServiceCollectionExtensions.cs b/src/Resiliency/NBB.Resiliency/ServiceCollectionExtensions.cs deleted file mode 100644 index 72141916..00000000 --- a/src/Resiliency/NBB.Resiliency/ServiceCollectionExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; - -namespace NBB.Resiliency -{ - public static class ServiceCollectionExtensions - { - public static void AddResiliency(this IServiceCollection serviceCollection) - { - serviceCollection.AddSingleton(); - } - } -} diff --git a/test/Benchmarks/EventStoreBenchmarks/EventStoreBenchmark.cs b/test/Benchmarks/EventStoreBenchmarks/EventStoreBenchmark.cs index 54128d79..e17e92c1 100644 --- a/test/Benchmarks/EventStoreBenchmarks/EventStoreBenchmark.cs +++ b/test/Benchmarks/EventStoreBenchmarks/EventStoreBenchmark.cs @@ -1,16 +1,13 @@ using BenchmarkDotNet.Attributes; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using NBB.Core.Abstractions; using NBB.EventStore; using NBB.EventStore.Abstractions; using NBB.EventStore.AdoNet; using NBB.EventStore.AdoNet.Migrations; using NBB.EventStore.AdoNet.Multitenancy; -using NBB.GetEventStore; using NBB.MultiTenancy.Abstractions; using NBB.MultiTenancy.Abstractions.Context; -using NBB.MultiTenancy.Abstractions.Hosting; using NBB.SQLStreamStore; using NBB.SQLStreamStore.Migrations; using System; @@ -66,13 +63,6 @@ public void GlobalSetupSqlStreamStoreSave() services.AddSqlStreamStore()); } - [GlobalSetup(Target = nameof(GetEventStoreSave))] - public void GlobalSetupGetEventStoreSave() - { - _container = BuildServiceProvider((services, _) => - services.AddGetEventStore()); - } - [GlobalSetup(Target = nameof(NBBEventStoreLoad))] public void GlobalSetupNBBEventStoreLoad() @@ -95,13 +85,6 @@ public void GlobalSetupSqlStreamStoreLoad() SeedEventRepository(_loadTestStream); } - [GlobalSetup(Target = nameof(GetEventStoreLoad))] - public void GlobalSetupGetEventStoreLoad() - { - GlobalSetupGetEventStoreSave(); - SeedEventRepository(_loadTestStream); - } - [Benchmark] public void NBBEventStoreSave() { @@ -120,12 +103,6 @@ public void SqlStreamStoreSave() EventStoreSave(); } - //[Benchmark] - public void GetEventStoreSave() - { - EventStoreSave(); - } - [Benchmark] public void NBBEventStoreLoad() { @@ -145,13 +122,6 @@ public void SqlStreamStoreLoad() } - //[Benchmark] - public void GetEventStoreLoad() - { - EventStoreLoad(); - } - - public void EventStoreSave() { using (var scope = _container.CreateScope()) diff --git a/test/Benchmarks/EventStoreBenchmarks/EventStoreBenchmarks.csproj b/test/Benchmarks/EventStoreBenchmarks/EventStoreBenchmarks.csproj index 7bf7f9fc..0f5bdf07 100644 --- a/test/Benchmarks/EventStoreBenchmarks/EventStoreBenchmarks.csproj +++ b/test/Benchmarks/EventStoreBenchmarks/EventStoreBenchmarks.csproj @@ -45,11 +45,9 @@ - - diff --git a/test/Integration/NBB.EventStore.IntegrationTests/EventStoreDBIntegrationTests.cs b/test/Integration/NBB.EventStore.IntegrationTests/EventStoreDBIntegrationTests.cs index 49a126d4..79a15459 100644 --- a/test/Integration/NBB.EventStore.IntegrationTests/EventStoreDBIntegrationTests.cs +++ b/test/Integration/NBB.EventStore.IntegrationTests/EventStoreDBIntegrationTests.cs @@ -14,7 +14,6 @@ using System.IO; using System.Reflection; using System.Threading; -using MediatR; using Xunit; namespace NBB.EventStore.IntegrationTests @@ -36,7 +35,7 @@ public void EventStore_AppendEventsToStreamAsync_with_expected_version_should_be using (var scope = container.CreateScope()) { - var eventStore = scope.ServiceProvider.GetService(); + var eventStore = scope.ServiceProvider.GetRequiredService(); for (var i = 0; i < threadCount; i++) { @@ -46,7 +45,7 @@ public void EventStore_AppendEventsToStreamAsync_with_expected_version_should_be try { eventStore.AppendEventsToStreamAsync(stream, - new[] { new TestEvent(Guid.NewGuid()) }, streamVersion, + new[] {new TestEvent(Guid.NewGuid())}, streamVersion, CancellationToken.None) .Wait(); } @@ -83,14 +82,14 @@ public void EventStore_AppendEventsToStreamAsync_with_expected_version_any_shoul using (var scope = container.CreateScope()) { - var eventStore = scope.ServiceProvider.GetService(); + var eventStore = scope.ServiceProvider.GetRequiredService(); for (var i = 0; i < threadCount; i++) { var t = new Thread(() => { eventStore.AppendEventsToStreamAsync(stream, - new[] { new TestEvent(Guid.NewGuid()) }, null, CancellationToken.None).Wait(); + new[] {new TestEvent(Guid.NewGuid())}, null, CancellationToken.None).Wait(); }); t.Start(); threads.Add(t); @@ -107,7 +106,6 @@ public void EventStore_AppendEventsToStreamAsync_with_expected_version_any_shoul } } - private static IServiceProvider BuildAdoRepoServiceProvider() { var configurationBuilder = new ConfigurationBuilder() @@ -135,11 +133,11 @@ private static IServiceProvider BuildAdoRepoServiceProvider() .WithAdoNetEventRepository(); services.AddMultitenancy(configuration, _ => - { - services.AddSingleton(Mock.Of(x => - x.TenantContext == new TenantContext(new Tenant(Guid.NewGuid(), null, false)))); - services.WithMultiTenantAdoNetEventRepository(); - }); + { + services.AddSingleton(Mock.Of(x => + x.TenantContext == new TenantContext(new Tenant(Guid.NewGuid(), null, false)))); + services.WithMultiTenantAdoNetEventRepository(); + }); var container = services.BuildServiceProvider(); @@ -152,5 +150,5 @@ private static void PrepareDb() } } - public record TestEvent(Guid EventId) : INotification; -} + public record TestEvent(Guid EventId); +} \ No newline at end of file diff --git a/test/Integration/NBB.EventStore.IntegrationTests/EventStoreMessagingIntegrationTests.cs b/test/Integration/NBB.EventStore.IntegrationTests/EventStoreMessagingIntegrationTests.cs deleted file mode 100644 index 34383fff..00000000 --- a/test/Integration/NBB.EventStore.IntegrationTests/EventStoreMessagingIntegrationTests.cs +++ /dev/null @@ -1,117 +0,0 @@ -using FluentAssertions; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Moq; -using NBB.Core.Abstractions; -using NBB.Core.Pipeline; -using NBB.EventStore.Abstractions; -using NBB.EventStore.Host; -using NBB.EventStore.InMemory; -using NBB.EventStore.MessagingExtensions; -using NBB.Messaging.Abstractions; -using NBB.Messaging.InProcessMessaging.Extensions; -using NBB.MultiTenancy.Abstractions; -using NBB.MultiTenancy.Abstractions.Context; -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using System.Threading; -using System.Threading.Tasks; -using Xunit; - -namespace NBB.EventStore.IntegrationTests -{ - public class EventStoreMessagingIntegrationTests : IClassFixture - { - [Fact] - public async Task EventStore_Messaging_Publish_Subscribe() - { - Guid eventId = Guid.NewGuid(); - object hostMessageReceived = null; - var hostMessageReceivedEvent = new ManualResetEventSlim(); - - void HostMessageReceived(object @event) - { - hostMessageReceived = @event; - hostMessageReceivedEvent.Set(); - } - - var container = BuildMessagingServiceProvider(HostMessageReceived); - var stream = Guid.NewGuid().ToString(); - - using (var scope = container.CreateScope()) - { - var host = scope.ServiceProvider.GetService(); - try - { - await host.StartAsync(CancellationToken.None); - - var eventStore = scope.ServiceProvider.GetService(); - eventStore.AppendEventsToStreamAsync(stream, new[] {new TestEvent(eventId)}, null, - CancellationToken.None).Wait(); - - hostMessageReceivedEvent.Wait(5000); - } - finally - { - await host.StopAsync(CancellationToken.None); - } - } - - hostMessageReceived.Should().NotBeNull(); - ((TestEvent)hostMessageReceived).EventId.Should().Be(eventId); - } - - private static IServiceProvider BuildMessagingServiceProvider(Action hostMessageReceived = null) - { - var configurationBuilder = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); - - var environment = Environment.GetEnvironmentVariable("NETCORE_ENVIRONMENT"); - var isDevelopment = string.Equals(environment, "development", StringComparison.OrdinalIgnoreCase); - - if (isDevelopment) - { - configurationBuilder.AddUserSecrets(Assembly.GetExecutingAssembly()); - } - - var configuration = configurationBuilder.Build(); - - - var services = new ServiceCollection(); - services.AddSingleton(configuration); - services.AddLogging(); - - services.AddEventStore() - .WithNewtownsoftJsonEventStoreSeserializer() - .WithInMemoryEventRepository() - .WithMessagingExtensions(builder => - { - builder.Options.SerDes.DeserializationType = DeserializationType.Dynamic; - builder.Options.SerDes.DynamicDeserializationScannedAssemblies = new[] - { - typeof(TestEventMessaging).Assembly - }; - }); - - services.AddInProcessMessaging(); - - services.AddEventStoreHost() - .UsePipeline(config => config - .Use((e, ct, next) => - { - hostMessageReceived?.Invoke(e); - return next(); - }) - ); - - var container = services.BuildServiceProvider(); - return container; - } - } - - public record TestEventMessaging; -} diff --git a/test/Integration/NBB.EventStore.IntegrationTests/NBB.EventStore.IntegrationTests.csproj b/test/Integration/NBB.EventStore.IntegrationTests/NBB.EventStore.IntegrationTests.csproj index 4f76305d..a6807334 100644 --- a/test/Integration/NBB.EventStore.IntegrationTests/NBB.EventStore.IntegrationTests.csproj +++ b/test/Integration/NBB.EventStore.IntegrationTests/NBB.EventStore.IntegrationTests.csproj @@ -40,7 +40,6 @@ - diff --git a/test/UnitTests/EventStore/NBB.GetEventStore.Tests/GetEventStoreSubscriberTests.cs b/test/UnitTests/EventStore/NBB.GetEventStore.Tests/GetEventStoreSubscriberTests.cs deleted file mode 100644 index df27e45e..00000000 --- a/test/UnitTests/EventStore/NBB.GetEventStore.Tests/GetEventStoreSubscriberTests.cs +++ /dev/null @@ -1,67 +0,0 @@ -using FluentAssertions; -using Microsoft.Extensions.Logging; -using Moq; -using NBB.GetEventStore.Internal; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace NBB.GetEventStore.Tests -{ - public record TestEvent1(int SequenceNumber, Guid EventId, DateTime CreationDate); - public record TestEvent2(int SequenceNumber, Guid EventId, DateTime CreationDate); - - public class GetEventStoreSubscriberTests - { - - //[Fact] - public async Task Should_Receive_Events_From_Subscription() - { - //Arrange - var serDes = new SerDes(); - var stream1 = "teststream-1"; - var stream2 = "teststream-2"; - var events1 = new List - { - new TestEvent1( - CreationDate: DateTime.Now, - EventId: Guid.NewGuid(), - SequenceNumber: 0 - ), - new TestEvent1( - CreationDate: DateTime.Now, - EventId: Guid.NewGuid(), - SequenceNumber: 1 - ) - }; - var events2 = new List - { - new TestEvent2( - CreationDate: DateTime.Now, - EventId: Guid.NewGuid(), - SequenceNumber: 0 - ) - }; - - var totalEventsCount = events1.Count + events2.Count; - var sut = new GetEventStoreSubscriber(serDes, Mock.Of>()); - var pub = new GetEventStoreClient(serDes, Mock.Of>()); - await pub.AppendEventsToStreamAsync(stream1, events1, null, CancellationToken.None); - await pub.AppendEventsToStreamAsync(stream2, events2, null, CancellationToken.None); - var messagesReceived = 0; - var cts = new CancellationTokenSource(); - //Act - await sut.SubscribeToAllAsync(message => - { - messagesReceived++; - if (messagesReceived >= totalEventsCount) - cts.Cancel(); - return Task.CompletedTask; - }, cts.Token); - - //Assert - messagesReceived.Should().Be(totalEventsCount); - } - } -} diff --git a/test/UnitTests/EventStore/NBB.GetEventStore.Tests/NBB.GetEventStore.Tests.csproj b/test/UnitTests/EventStore/NBB.GetEventStore.Tests/NBB.GetEventStore.Tests.csproj deleted file mode 100644 index 68b74b4d..00000000 --- a/test/UnitTests/EventStore/NBB.GetEventStore.Tests/NBB.GetEventStore.Tests.csproj +++ /dev/null @@ -1,27 +0,0 @@ - - - - SAK - SAK - SAK - SAK - - - - Exe - net5.0 - - - - - - - - - - - - - - - diff --git a/test/UnitTests/Messaging/NBB.Messaging.Abstractions.Tests/MessageSerDesTests.cs b/test/UnitTests/Messaging/NBB.Messaging.Abstractions.Tests/MessageSerDesTests.cs index 002623bf..433b02d6 100644 --- a/test/UnitTests/Messaging/NBB.Messaging.Abstractions.Tests/MessageSerDesTests.cs +++ b/test/UnitTests/Messaging/NBB.Messaging.Abstractions.Tests/MessageSerDesTests.cs @@ -3,7 +3,6 @@ using System.Reflection; using FluentAssertions; using Moq; -using NBB.Messaging.DataContracts; using Xunit; namespace NBB.Messaging.Abstractions.Tests diff --git a/test/UnitTests/Messaging/NBB.Messaging.Abstractions.Tests/MessageTypeRegistryTests.cs b/test/UnitTests/Messaging/NBB.Messaging.Abstractions.Tests/MessageTypeRegistryTests.cs index 36ae8058..e889ca07 100644 --- a/test/UnitTests/Messaging/NBB.Messaging.Abstractions.Tests/MessageTypeRegistryTests.cs +++ b/test/UnitTests/Messaging/NBB.Messaging.Abstractions.Tests/MessageTypeRegistryTests.cs @@ -1,7 +1,6 @@ using System; using System.Reflection; using FluentAssertions; -using NBB.Messaging.DataContracts; using Xunit; namespace NBB.Messaging.Abstractions.Tests diff --git a/test/UnitTests/Messaging/NBB.Messaging.Abstractions.Tests/TopicRegistryTests.cs b/test/UnitTests/Messaging/NBB.Messaging.Abstractions.Tests/TopicRegistryTests.cs index fcce1f85..c1056f9e 100644 --- a/test/UnitTests/Messaging/NBB.Messaging.Abstractions.Tests/TopicRegistryTests.cs +++ b/test/UnitTests/Messaging/NBB.Messaging.Abstractions.Tests/TopicRegistryTests.cs @@ -2,7 +2,6 @@ using FluentAssertions; using Microsoft.Extensions.Configuration; using Moq; -using NBB.Messaging.DataContracts; using Xunit; namespace NBB.Messaging.Abstractions.Tests diff --git a/test/UnitTests/Messaging/NBB.Messaging.DataContracts.Tests/NBB.Messaging.DataContracts.Tests.csproj b/test/UnitTests/Messaging/NBB.Messaging.DataContracts.Tests/NBB.Messaging.DataContracts.Tests.csproj index 9f06b71e..2707a45b 100644 --- a/test/UnitTests/Messaging/NBB.Messaging.DataContracts.Tests/NBB.Messaging.DataContracts.Tests.csproj +++ b/test/UnitTests/Messaging/NBB.Messaging.DataContracts.Tests/NBB.Messaging.DataContracts.Tests.csproj @@ -16,7 +16,6 @@ - diff --git a/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessageBusSubscriberServceTests.cs b/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessageBusSubscriberServceTests.cs index 5730480d..f78c538c 100644 --- a/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessageBusSubscriberServceTests.cs +++ b/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessageBusSubscriberServceTests.cs @@ -3,7 +3,6 @@ using Moq; using NBB.Core.Pipeline; using NBB.Messaging.Abstractions; -using NBB.Messaging.DataContracts; using System; using System.Collections.Generic; using System.Threading; diff --git a/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingHostBuilderTests.cs b/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingHostBuilderTests.cs index 8de66afa..6124c137 100644 --- a/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingHostBuilderTests.cs +++ b/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingHostBuilderTests.cs @@ -3,10 +3,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Moq; -using NBB.Core.Abstractions; using NBB.Core.Pipeline; using NBB.Messaging.Abstractions; -using NBB.Messaging.DataContracts; using NBB.Messaging.Host.Builder; using System; using System.Collections.Generic; diff --git a/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/CorrelationMiddlewareTests.cs b/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/CorrelationMiddlewareTests.cs index 3abf1385..b9159d0d 100644 --- a/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/CorrelationMiddlewareTests.cs +++ b/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/CorrelationMiddlewareTests.cs @@ -1,10 +1,8 @@ using System; using System.Threading.Tasks; using FluentAssertions; -using Moq; using NBB.Correlation; using NBB.Messaging.Abstractions; -using NBB.Messaging.DataContracts; using NBB.Messaging.Host.MessagingPipeline; using Xunit; @@ -18,9 +16,9 @@ public async void Should_setNewCorrelationId() { //Arrange var correlationMiddleWare = new CorrelationMiddleware(); - var sentMessage = Mock.Of(); + var sentMessage = new {Field = "value"}; Guid? correlationId = null; - var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); + var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); Task Next() { correlationId = CorrelationManager.GetCorrelationId(); return Task.CompletedTask; } @@ -39,7 +37,7 @@ public async void Should_takeCorrelationIdFromMessage() //Arrange var correlationMiddleWare = new CorrelationMiddleware(); var messageCorrelationId = Guid.NewGuid(); - var sentMessage = "Test"; + var sentMessage = "Test"; Guid? correlationId = null; var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); envelope.SetHeader(MessagingHeaders.CorrelationId, messageCorrelationId.ToString()); @@ -57,9 +55,9 @@ public async void Should_callNextPipelineMiddleware() { //Arrange var correlationMiddleWare = new CorrelationMiddleware(); - var sentMessage = Mock.Of(); + var sentMessage = new {Field = "value"}; bool isNextMiddlewareCalled = false; - var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); + var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); Task Next() { isNextMiddlewareCalled = true; return Task.CompletedTask; } @@ -71,4 +69,4 @@ public async void Should_callNextPipelineMiddleware() isNextMiddlewareCalled.Should().BeTrue(); } } -} +} \ No newline at end of file diff --git a/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/DefaultResiliencyMiddlewareTests.cs b/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/DefaultResiliencyMiddlewareTests.cs index 424b2f45..c57c55f0 100644 --- a/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/DefaultResiliencyMiddlewareTests.cs +++ b/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/DefaultResiliencyMiddlewareTests.cs @@ -3,10 +3,8 @@ using FluentAssertions; using Microsoft.Extensions.Logging; using Moq; -using NBB.Core.Abstractions; -using NBB.Messaging.DataContracts; +using NBB.Messaging.Abstractions; using NBB.Messaging.Host.MessagingPipeline; -using NBB.Resiliency; using Polly; using Xunit; @@ -18,17 +16,14 @@ public class DefaultResiliencyMiddlewareTests public async void Should_callNextPipelineMiddleware() { //Arrange - var dummyPolicy = Policy.Handle().RetryAsync(0); - + var dummyPolicy = Policy.Handle().RetryAsync(0); + var resiliencyMiddleware = new DefaultResiliencyMiddleware( - Mock.Of(x => - x.GetConcurencyExceptionPolicy(It.IsAny>()) == dummyPolicy && - x.GetOutOfOrderPolicy(It.IsAny>()) == dummyPolicy), Mock.Of>()); - var sentMessage = Mock.Of(); + var sentMessage = new { Field = "value"}; var isNextMiddlewareCalled = false; - var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); + var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); Task Next() { isNextMiddlewareCalled = true; return Task.CompletedTask; } @@ -39,80 +34,18 @@ public async void Should_callNextPipelineMiddleware() isNextMiddlewareCalled.Should().BeTrue(); } - [Fact] - public async void Should_callOutOfOrderResiliencyPolicy() - { - //Arrange - var dummyPolicy = Policy.Handle().RetryAsync(0); - var outOfOrderPoliyCalled = false; - var outOfOrderPolicy = Policy.Handle() - .FallbackAsync(ct => - { - outOfOrderPoliyCalled = true; - return Task.CompletedTask; - }); - - var resiliencyMiddleware = new DefaultResiliencyMiddleware( - Mock.Of(x => - x.GetConcurencyExceptionPolicy(It.IsAny>()) == dummyPolicy && - x.GetOutOfOrderPolicy(It.IsAny>()) == outOfOrderPolicy), - Mock.Of>()); - - var sentMessage = Mock.Of(); - var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); - - Task Next() => throw new OutOfOrderMessageException(); - - //Act - await resiliencyMiddleware.Invoke(envelope, default, Next); - //Assert - outOfOrderPoliyCalled.Should().BeTrue(); - } - - [Fact] - public async void Should_callConcurrencyResiliencyPolicy() - { - //Arrange - var dummyPolicy = Policy.Handle().RetryAsync(0); - var concurrencyPoliyCalled = false; - var concurrencyPolicy = Policy.Handle() - .FallbackAsync(ct => - { - concurrencyPoliyCalled = true; - return Task.CompletedTask; - }); - - var resiliencyMiddleware = new DefaultResiliencyMiddleware( - Mock.Of(x => - x.GetConcurencyExceptionPolicy(It.IsAny>()) == concurrencyPolicy && - x.GetOutOfOrderPolicy(It.IsAny>()) == dummyPolicy), - Mock.Of>()); - - var sentMessage = Mock.Of(); - var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); - - Task Next() => throw new ConcurrencyException("message"); - - //Act - await resiliencyMiddleware.Invoke(envelope, default, Next); - //Assert - concurrencyPoliyCalled.Should().BeTrue(); - } - + [Fact] public void Should_throwGenericException() { //Arrange - var dummyPolicy = Policy.Handle().RetryAsync(0); - var mockedLogger = Mock.Of>(); + var dummyPolicy = Policy.Handle().RetryAsync(0); + var mockedLogger = Mock.Of>(); var resiliencyMiddleware = new DefaultResiliencyMiddleware( - Mock.Of(x => - x.GetConcurencyExceptionPolicy(It.IsAny>()) == dummyPolicy && - x.GetOutOfOrderPolicy(It.IsAny>()) == dummyPolicy), mockedLogger); - var sentMessage = Mock.Of(); - var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); + var sentMessage = new { Field = "value"}; + var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); Task Next() => throw new ApplicationException(); @@ -130,16 +63,13 @@ async Task Action() public void Should_throwPolicyException() { //Arrange - var dummyPolicy = Policy.Handle().RetryAsync(1); - var mockedLogger = Mock.Of>(); + var dummyPolicy = Policy.Handle().RetryAsync(1); + var mockedLogger = Mock.Of>(); var resiliencyMiddleware = new DefaultResiliencyMiddleware( - Mock.Of(x => - x.GetConcurencyExceptionPolicy(It.IsAny>()) == dummyPolicy && - x.GetOutOfOrderPolicy(It.IsAny>()) == dummyPolicy), mockedLogger); - var sentMessage = Mock.Of(); - var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); + var sentMessage = new { Field = "value"}; + var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); Task Next() => throw new ApplicationException(); diff --git a/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/ExceptionHandlingMiddlewareTests.cs b/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/ExceptionHandlingMiddlewareTests.cs index 1b49cbe9..bda883bd 100644 --- a/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/ExceptionHandlingMiddlewareTests.cs +++ b/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/ExceptionHandlingMiddlewareTests.cs @@ -1,7 +1,7 @@ using FluentAssertions; using Microsoft.Extensions.Logging; using Moq; -using NBB.Messaging.DataContracts; +using NBB.Messaging.Abstractions; using NBB.Messaging.Host.MessagingPipeline; using System; using System.Threading.Tasks; @@ -17,8 +17,8 @@ public async void Should_logSuccessMessage() //Arrange var mockedLogger = Mock.Of>(); var correlationMiddleWare = new ExceptionHandlingMiddleware(mockedLogger); - var sentMessage = Mock.Of(); - var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); + var sentMessage = new { Field = "value"}; + var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); Task next() => Task.CompletedTask; @@ -35,8 +35,8 @@ public async void Should_logErrorMessageWhenExceptionIsThrown() //Arrange var mockedLogger = Mock.Of>(); var correlationMiddleWare = new ExceptionHandlingMiddleware(mockedLogger); - var sentMessage = Mock.Of(); - var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); + var sentMessage = new { Field = "value"}; + var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); Task next() => throw new ApplicationException(); @@ -45,7 +45,10 @@ public async void Should_logErrorMessageWhenExceptionIsThrown() { await correlationMiddleWare.Invoke(envelope, default, next); } - catch { } + catch + { + // ignored + } //Assert VerifyLog(mockedLogger, LogLevel.Error, nameof(ApplicationException)); @@ -56,9 +59,9 @@ public async void Should_callNextPipelineMiddleware() { //Arrange var executionTimeMiddleware = new ExceptionHandlingMiddleware(Mock.Of>()); - var sentMessage = Mock.Of(); + var sentMessage = new { Field = "value"}; bool isNextMiddlewareCalled = false; - var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); + var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); Task next() { isNextMiddlewareCalled = true; return Task.CompletedTask; } diff --git a/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/MediatRMiddlewareTests.cs b/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/MediatRMiddlewareTests.cs index fd57b823..ad5d01af 100644 --- a/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/MediatRMiddlewareTests.cs +++ b/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/MediatRMiddlewareTests.cs @@ -3,7 +3,7 @@ using FluentAssertions; using MediatR; using Moq; -using NBB.Messaging.DataContracts; +using NBB.Messaging.Abstractions; using NBB.Messaging.Host.MessagingPipeline; using Xunit; @@ -56,9 +56,10 @@ public void Should_throwExceptionForUnhandledMessageType() { //Arrange var mediatRMiddleware = new MediatRMiddleware(Mock.Of()); - var sentMessage = Mock.Of(); - var envelope = new MessagingEnvelope(new System.Collections.Generic.Dictionary(), - sentMessage); + var sentMessage = new {Field = "value"}; + + var envelope = + new MessagingEnvelope(new System.Collections.Generic.Dictionary(), sentMessage); Task Next() => Task.CompletedTask; @@ -95,15 +96,15 @@ Task Next() isNextMiddlewareCalled.Should().BeTrue(); } - public interface IMockingEventMessage : IMessage, INotification + public interface IMockingEventMessage : INotification { } - public interface IMockingCommandMessage : IMessage, IRequest + public interface IMockingCommandMessage : IRequest { } - public interface IMockingQueryMessage : IMessage, IRequest + public interface IMockingQueryMessage : IRequest { } } diff --git a/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/MessagingPipelineExtensionsTests.cs b/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/MessagingPipelineExtensionsTests.cs index 7f050743..181a9baa 100644 --- a/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/MessagingPipelineExtensionsTests.cs +++ b/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingPipeline/MessagingPipelineExtensionsTests.cs @@ -1,6 +1,6 @@ using Moq; using NBB.Core.Pipeline; -using NBB.Messaging.DataContracts; +using NBB.Messaging.Abstractions; using NBB.Messaging.Host.MessagingPipeline; using System; using Xunit; diff --git a/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingTopicSubscriberServiceTests.cs b/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingTopicSubscriberServiceTests.cs index 71ba0ad5..759ee13b 100644 --- a/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingTopicSubscriberServiceTests.cs +++ b/test/UnitTests/Messaging/NBB.Messaging.Host.Tests/MessagingTopicSubscriberServiceTests.cs @@ -3,7 +3,6 @@ using Moq; using NBB.Core.Pipeline; using NBB.Messaging.Abstractions; -using NBB.Messaging.DataContracts; using System; using System.Collections.Generic; using System.Threading; diff --git a/test/UnitTests/Messaging/NBB.Messaging.InProcessMessaging.Tests/StorageTests.cs b/test/UnitTests/Messaging/NBB.Messaging.InProcessMessaging.Tests/StorageTests.cs index 300a9102..6eb818b4 100644 --- a/test/UnitTests/Messaging/NBB.Messaging.InProcessMessaging.Tests/StorageTests.cs +++ b/test/UnitTests/Messaging/NBB.Messaging.InProcessMessaging.Tests/StorageTests.cs @@ -1,5 +1,4 @@ using FluentAssertions; -using NBB.Messaging.DataContracts; using NBB.Messaging.InProcessMessaging.Internal; using System.Collections.Generic; using System.Threading; @@ -10,7 +9,7 @@ namespace NBB.Messaging.InProcessMessaging.Tests { public class StorageTests { - public class TestMessage : IMessage + public class TestMessage { public IDictionary Headers => new Dictionary(); diff --git a/test/UnitTests/Messaging/NBB.Messaging.MultiTenancy.Tests/MessageBusPublisherDecoratorTests.cs b/test/UnitTests/Messaging/NBB.Messaging.MultiTenancy.Tests/MessageBusPublisherDecoratorTests.cs index df774877..648120ae 100644 --- a/test/UnitTests/Messaging/NBB.Messaging.MultiTenancy.Tests/MessageBusPublisherDecoratorTests.cs +++ b/test/UnitTests/Messaging/NBB.Messaging.MultiTenancy.Tests/MessageBusPublisherDecoratorTests.cs @@ -5,7 +5,6 @@ using FluentAssertions; using Moq; using NBB.Messaging.Abstractions; -using NBB.Messaging.DataContracts; using NBB.MultiTenancy.Abstractions; using NBB.MultiTenancy.Abstractions.Context; using Xunit; diff --git a/test/UnitTests/MultiTenancy/NBB.MultiTenancy.Identification.Messaging.Tests/TenantIdHeaderMessagingTokenResolverTests.cs b/test/UnitTests/MultiTenancy/NBB.MultiTenancy.Identification.Messaging.Tests/TenantIdHeaderMessagingTokenResolverTests.cs index 5657b918..67fd869f 100644 --- a/test/UnitTests/MultiTenancy/NBB.MultiTenancy.Identification.Messaging.Tests/TenantIdHeaderMessagingTokenResolverTests.cs +++ b/test/UnitTests/MultiTenancy/NBB.MultiTenancy.Identification.Messaging.Tests/TenantIdHeaderMessagingTokenResolverTests.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using FluentAssertions; using NBB.Messaging.Abstractions; -using NBB.Messaging.DataContracts; using Xunit; namespace NBB.MultiTenancy.Identification.Messaging.Tests diff --git a/test/UnitTests/Orchestration/NBB.ProcessManager.Tests/ProcessManagerInstanceUnitTests.cs b/test/UnitTests/Orchestration/NBB.ProcessManager.Tests/ProcessManagerInstanceUnitTests.cs index 484b53dd..c5077fe1 100644 --- a/test/UnitTests/Orchestration/NBB.ProcessManager.Tests/ProcessManagerInstanceUnitTests.cs +++ b/test/UnitTests/Orchestration/NBB.ProcessManager.Tests/ProcessManagerInstanceUnitTests.cs @@ -28,7 +28,8 @@ public async Task TestRepo() var definition = new OrderProcessManager3(); var instance = new Instance(definition); - var identitySelector = ((IDefinition) definition).GetCorrelationFilter(); + var identitySelector = + ((IDefinition) definition).GetCorrelationFilter(); if (identitySelector != null) instance = await _fixture.Repository.Get(definition, identitySelector(@event), CancellationToken.None); @@ -53,11 +54,10 @@ public OrderProcessManagerNoCorrelation() { StartWith() .SetState((orderCreated, state) => - { - var newState = state.Data; - newState.Amount = 100; - return newState; - }) + state.Data with + { + Amount = 100 + }) .PublishEvent((orderCreated, state) => new OrderCompleted(orderCreated.OrderId, 100, 0, 0)); } } @@ -82,12 +82,13 @@ public OrderProcessManager2() StartWith() .PublishEvent((orderCreated, state) => new OrderCompleted(orderCreated.OrderId, 100, 0, 0)) - .SetState((orderCreated, state) => - { - var newState = state.Data; - newState.Amount = state.Data.Amount + 100; - return newState; - }); + .SetState((orderCreated, state + ) => + state.Data with + { + Amount = state + .Data.Amount + 100 + }); } } @@ -113,25 +114,20 @@ class OrderProcessManager3 : AbstractDefinition public OrderProcessManager3() { Event(configurator => configurator.CorrelateById(orderCreated => orderCreated.OrderId)); - Event(configurator => configurator.CorrelateById(paymentReceived => paymentReceived.OrderId)); + Event(configurator => + configurator.CorrelateById(paymentReceived => paymentReceived.OrderId)); StartWith() .SetState((orderCreated, state) => - { - var newState = state.Data; - newState.Amount = 100; - newState.OrderId = orderCreated.OrderId; - return newState; - }) + state.Data with + { + Amount = 100, + OrderId = orderCreated.OrderId + }) .PublishEvent((orderCreated, state) => new OrderCompleted(orderCreated.OrderId, 100, 0, 0)); When() - .SetState((@event, data) => - { - var newState = data.Data; - newState.IsPaid = true; - return newState; - }) + .SetState((@event, state) => state.Data with {IsPaid = true}) .Then((ev, state) => { var effect = MessageBus.Publish(new DoPayment()); @@ -186,42 +182,31 @@ class OrderProcessManager5 : AbstractDefinition public OrderProcessManager5() { Event(configurator => configurator.CorrelateById(orderCreated => orderCreated.OrderId)); - Event(configurator => configurator.CorrelateById(orderPaymentCreated => orderPaymentCreated.OrderId)); + Event(configurator => + configurator.CorrelateById(orderPaymentCreated => orderPaymentCreated.OrderId)); StartWith() - .SetState((@event, data) => - { - var newState = data.Data; - newState.IsPaid = true; - return newState; - }); + .SetState((@event, data) => data.Data with {IsPaid = true}); When((@event, data) => true) - .SetState((@event, data) => - { - var newState = data.Data; - newState.Amount = 100; - return newState; - }); + .SetState((@event, data) => data.Data with {Amount = 100}); When((@event, data) => data.Data.Amount < 100) .SetState((@event, data) => - { - var newState = data.Data; - newState.Amount += 20; - newState.IsPaid = false; - return newState; - }) + data.Data with + { + Amount = data.Data.Amount + 20, + IsPaid = false + }) .Complete((@event, data) => data.Data.IsPaid); When((@event, data) => data.Data.Amount >= 100) .SetState((@event, data) => - { - var newState = data.Data; - newState.Amount += 10; - newState.IsPaid = false; - return newState; - }) + data.Data with + { + Amount = data.Data.Amount + 10, + IsPaid = false + }) .Complete((@event, data) => data.Data.IsPaid); } } @@ -251,29 +236,20 @@ class OrderProcessManager6 : AbstractDefinition public OrderProcessManager6() { Event(configurator => configurator.CorrelateById(orderCreated => orderCreated.OrderId)); - Event(configurator => configurator.CorrelateById(orderCompleted => orderCompleted.OrderId)); - Event(configurator => configurator.CorrelateById(orderPaymentCreated => orderPaymentCreated.OrderId)); + Event(configurator => + configurator.CorrelateById(orderCompleted => orderCompleted.OrderId)); + Event(configurator => + configurator.CorrelateById(orderPaymentCreated => orderPaymentCreated.OrderId)); StartWith() - .SetState((@event, data) => - { - var newState = data.Data; - newState.OrderId = @event.OrderId; - return newState; - }); + .SetState((@event, data) => data.Data with {OrderId = @event.OrderId}); When() .Complete(); When() - .SetState((@event, data) => - { - var newState = data.Data; - newState.IsPaid = true; - return newState; - }) + .SetState((@event, data) => data.Data with {IsPaid = true}) .Complete(); - } } @@ -311,14 +287,14 @@ public OrderProcessManager7() } } - public struct OrderProcessManagerData + public record OrderProcessManagerData { - public Guid OrderId { get; set; } - public int SiteId { get; set; } - public int DocumentId { get; set; } - public int UserId { get; set; } - public decimal Amount { get; set; } - public bool IsPaid { get; set; } - public bool IsShipped { get; set; } + public Guid OrderId { get; init; } + public int SiteId { get; init; } + public int DocumentId { get; init; } + public int UserId { get; init; } + public decimal Amount { get; init; } + public bool IsPaid { get; init; } + public bool IsShipped { get; init; } } } \ No newline at end of file