From bee51653086f40d3da46cc045898aca9c06fd989 Mon Sep 17 00:00:00 2001 From: Christopher Mann Date: Mon, 22 Apr 2024 10:16:45 +0200 Subject: [PATCH] Update to Rebus 8 (#15) * Upgrade rebus packages * Support usage of the in-memory transport as subscription store --- .../Rebus.Configuration.Abstractions.csproj | 2 +- .../Rebus.Configuration.MsmqSelectors.csproj | 2 +- .../DefaultTransportSelector.cs | 13 ++++++- ...us.Configuration.SqlServerSelectors.csproj | 2 +- .../Rebus.Operations.Core.csproj | 2 +- .../Rebus.SimpleInjector.csproj | 4 +- .../DefaultTransportSelectorTests.cs | 37 +++++++++++++++++-- .../SelectorTests.cs | 2 +- test/Rebus.Operations.Tests/RebusTestBase.cs | 3 +- .../Rebus.OperationsDB.Tests/DatabaseTests.cs | 3 +- .../Rebus.OperationsDB.Tests.csproj | 4 +- .../SimpleInjectorTestBase.cs | 1 - 12 files changed, 56 insertions(+), 19 deletions(-) diff --git a/src/Rebus.Configuration/Rebus.Configuration.Abstractions/Rebus.Configuration.Abstractions.csproj b/src/Rebus.Configuration/Rebus.Configuration.Abstractions/Rebus.Configuration.Abstractions.csproj index 85e3765..27b8945 100644 --- a/src/Rebus.Configuration/Rebus.Configuration.Abstractions/Rebus.Configuration.Abstractions.csproj +++ b/src/Rebus.Configuration/Rebus.Configuration.Abstractions/Rebus.Configuration.Abstractions.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/Rebus.Configuration/Rebus.Configuration.MsmqSelectors/Rebus.Configuration.MsmqSelectors.csproj b/src/Rebus.Configuration/Rebus.Configuration.MsmqSelectors/Rebus.Configuration.MsmqSelectors.csproj index 7eda0c2..a85596d 100644 --- a/src/Rebus.Configuration/Rebus.Configuration.MsmqSelectors/Rebus.Configuration.MsmqSelectors.csproj +++ b/src/Rebus.Configuration/Rebus.Configuration.MsmqSelectors/Rebus.Configuration.MsmqSelectors.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/Rebus.Configuration/Rebus.Configuration.Selectors/DefaultTransportSelector.cs b/src/Rebus.Configuration/Rebus.Configuration.Selectors/DefaultTransportSelector.cs index a1a7ed9..288e66b 100644 --- a/src/Rebus.Configuration/Rebus.Configuration.Selectors/DefaultTransportSelector.cs +++ b/src/Rebus.Configuration/Rebus.Configuration.Selectors/DefaultTransportSelector.cs @@ -35,7 +35,7 @@ protected override void ConfigureBusType(string busType, string queueName, Stand configurer.UseFileSystem(Path.Combine(path, "transport"), queueName); return; case "inmemory": - configurer.UseInMemoryTransport(_network, queueName); + configurer.UseInMemoryTransport(_network, queueName, ShouldStoreSubscriptions()); return; } } @@ -53,11 +53,20 @@ protected override void ConfigureBusTypeAsOneWayClient(string busType, StandardC configurer.UseFileSystemAsOneWayClient(path); return; case "inmemory": - configurer.UseInMemoryTransportAsOneWayClient(_network); + configurer.UseInMemoryTransportAsOneWayClient(_network, ShouldStoreSubscriptions()); return; } } + protected bool ShouldStoreSubscriptions() + { + var value = Configuration[$"{ConfigurationName}:storeSubscriptions"]; + if(string.IsNullOrWhiteSpace(value)) + return true; + if (bool.TryParse(value, out var result)) + return result; + throw new InvalidOperationException($"Invalid value for {ConfigurationName}::storeSubscriptions."); + } } \ No newline at end of file diff --git a/src/Rebus.Configuration/Rebus.Configuration.SqlServerSelectors/Rebus.Configuration.SqlServerSelectors.csproj b/src/Rebus.Configuration/Rebus.Configuration.SqlServerSelectors/Rebus.Configuration.SqlServerSelectors.csproj index d1b91be..59046d3 100644 --- a/src/Rebus.Configuration/Rebus.Configuration.SqlServerSelectors/Rebus.Configuration.SqlServerSelectors.csproj +++ b/src/Rebus.Configuration/Rebus.Configuration.SqlServerSelectors/Rebus.Configuration.SqlServerSelectors.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/Rebus.Operations/Rebus.Operations.Core/Rebus.Operations.Core.csproj b/src/Rebus.Operations/Rebus.Operations.Core/Rebus.Operations.Core.csproj index 9b99b6f..301e5af 100644 --- a/src/Rebus.Operations/Rebus.Operations.Core/Rebus.Operations.Core.csproj +++ b/src/Rebus.Operations/Rebus.Operations.Core/Rebus.Operations.Core.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/Rebus.SimpleInjector/Rebus.SimpleInjector.csproj b/src/Rebus.SimpleInjector/Rebus.SimpleInjector.csproj index a79e7a4..a0d2a8e 100644 --- a/src/Rebus.SimpleInjector/Rebus.SimpleInjector.csproj +++ b/src/Rebus.SimpleInjector/Rebus.SimpleInjector.csproj @@ -10,8 +10,8 @@ - - + + diff --git a/test/Rebus.Configuration/Rebus.Configuration.Selectors.Tests/DefaultTransportSelectorTests.cs b/test/Rebus.Configuration/Rebus.Configuration.Selectors.Tests/DefaultTransportSelectorTests.cs index e59836b..a742154 100644 --- a/test/Rebus.Configuration/Rebus.Configuration.Selectors.Tests/DefaultTransportSelectorTests.cs +++ b/test/Rebus.Configuration/Rebus.Configuration.Selectors.Tests/DefaultTransportSelectorTests.cs @@ -1,4 +1,5 @@ -using Rebus.Transport; +using Rebus.Subscriptions; +using Rebus.Transport; using Rebus.Transport.InMem; using Xunit; @@ -50,14 +51,44 @@ public void Configures_As_InMemory() { c.OneWayTransport(selector); }, true) - .AssertConfigured("Rebus.Transport.InMem.InMemTransport"); + .AssertConfigured("Rebus.Transport.InMem.InMemTransport") + .AssertConfigured("Rebus.Transport.InMem.InMemTransport"); ConfigureAndGetContainer(c => { c.Transport(selector, "dummy"); }, true) - .AssertConfigured("Rebus.Transport.InMem.InMemTransport"); + .AssertConfigured("Rebus.Transport.InMem.InMemTransport") + .AssertConfigured("Rebus.Transport.InMem.InMemTransport"); + } + + [Fact] + public void Configures_As_InMemory_Without_Subscription_Store() + { + var deps = SetupDeps(new Dictionary + { + { "bus:type", "inmemory" }, + { "bus:storeSubscriptions", "false" } + }); + + + var selector = new DefaultTransportSelector(new InMemNetwork(), deps.Configuration, deps.Logger); + + ConfigureAndGetContainer(c => + { + c.OneWayTransport(selector); + }, true) + .AssertConfigured("Rebus.Transport.InMem.InMemTransport") + .AssertConfigured("Rebus.Persistence.Throwing.DisabledSubscriptionStorage"); + + + ConfigureAndGetContainer(c => + { + c.Transport(selector, "dummy"); + }, true) + .AssertConfigured("Rebus.Transport.InMem.InMemTransport") + .AssertConfigured("Rebus.Persistence.Throwing.DisabledSubscriptionStorage"); } [Fact] diff --git a/test/Rebus.Configuration/Rebus.Configuration.Selectors.Tests/SelectorTests.cs b/test/Rebus.Configuration/Rebus.Configuration.Selectors.Tests/SelectorTests.cs index 59d024b..0579667 100644 --- a/test/Rebus.Configuration/Rebus.Configuration.Selectors.Tests/SelectorTests.cs +++ b/test/Rebus.Configuration/Rebus.Configuration.Selectors.Tests/SelectorTests.cs @@ -29,7 +29,7 @@ protected RebusConfigurer CreateConfigurer(Action testSetup, bo var configure = Configure.With(someContainerAdapter); if(!noTransport) - configure.Transport(cfg => cfg.UseInMemoryTransport(new InMemNetwork(), "null")); + configure.Transport(cfg => cfg.UseInMemoryTransport(new InMemNetwork(), "null", false)); testSetup(configure); diff --git a/test/Rebus.Operations.Tests/RebusTestBase.cs b/test/Rebus.Operations.Tests/RebusTestBase.cs index ded3206..b8ada24 100644 --- a/test/Rebus.Operations.Tests/RebusTestBase.cs +++ b/test/Rebus.Operations.Tests/RebusTestBase.cs @@ -35,7 +35,7 @@ public async Task SetupRebus( Configure.With(activator) .Options(o => { - o.SimpleRetryStrategy(maxDeliveryAttempts: 1, secondLevelRetriesEnabled: true); + o.RetryStrategy(maxDeliveryAttempts: 1, secondLevelRetriesEnabled: true); }) .Transport(cfg => cfg.UseInMemoryTransport(rebusNetwork, "main")) .Routing(r => @@ -46,7 +46,6 @@ public async Task SetupRebus( } }) .Sagas(x => x.StoreInMemory()) - .Subscriptions(x=>x.StoreInMemory(new InMemorySubscriberStore())) .Logging(x=>x.Use(new RebusTestLogging(_output))) .Create(); diff --git a/test/Rebus.OperationsDB.Tests/DatabaseTests.cs b/test/Rebus.OperationsDB.Tests/DatabaseTests.cs index 2d2bbcd..b5953da 100644 --- a/test/Rebus.OperationsDB.Tests/DatabaseTests.cs +++ b/test/Rebus.OperationsDB.Tests/DatabaseTests.cs @@ -78,13 +78,12 @@ private async Task SetupAndRunWorkflow( .Routing(r => r.TypeBased().AddOperations("workflow")) .Options(x => { - x.SimpleRetryStrategy(secondLevelRetriesEnabled: true, errorDetailsHeaderMaxLength: 5, maxDeliveryAttempts: 5); + x.RetryStrategy(secondLevelRetriesEnabled: true, errorDetailsHeaderMaxLength: 5, maxDeliveryAttempts: 5); x.SetNumberOfWorkers(workers); x.EnableSimpleInjectorUnitOfWork(); }) .Logging(x=>x.MicrosoftExtensionsLogging(new XUnitLogger("rebus", _outputHelper, new XUnitLoggerOptions()))) - .Subscriptions(c => c.StoreInMemory()) .Timeouts(x=>x.StoreInMemory()) .Sagas(s => { diff --git a/test/Rebus.OperationsDB.Tests/Rebus.OperationsDB.Tests.csproj b/test/Rebus.OperationsDB.Tests/Rebus.OperationsDB.Tests.csproj index dec02b8..6d0e1a4 100644 --- a/test/Rebus.OperationsDB.Tests/Rebus.OperationsDB.Tests.csproj +++ b/test/Rebus.OperationsDB.Tests/Rebus.OperationsDB.Tests.csproj @@ -17,8 +17,8 @@ - - + + diff --git a/test/Rebus.SimpleInjector.Tests/SimpleInjectorTestBase.cs b/test/Rebus.SimpleInjector.Tests/SimpleInjectorTestBase.cs index 8b685e7..ff45fa7 100644 --- a/test/Rebus.SimpleInjector.Tests/SimpleInjectorTestBase.cs +++ b/test/Rebus.SimpleInjector.Tests/SimpleInjectorTestBase.cs @@ -41,7 +41,6 @@ public void SetupRebus(Container container, bool sendMode, string eventDestinati }) .Sagas(x => x.StoreInMemory()) - .Subscriptions(x=>x.StoreInMemory(new InMemorySubscriberStore())) .Logging(x=>x.Use(new RebusTestLogging(_output))) .Start();