From 294b1ac1e4ab5e34aa2f30f3abf92259a2dc92ee Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Sat, 12 Jun 2021 10:10:23 +0200 Subject: [PATCH 1/4] Convert RabbitMQ to v1 --- EventFlow.sln | 17 +++++++++++ .../EventFlow.RabbitMQ.Tests.csproj | 4 +-- .../Integration/RabbitMqTests.cs | 26 +++++++++-------- .../Integrations/RabbitMqPublisherTests.cs | 6 ++-- .../EventFlow.RabbitMQ.csproj | 4 +-- .../EventFlowOptionsRabbitMqExtensions.cs | 17 +++++------ .../Integrations/RabbitConnection.cs | 20 +++++++------ .../Integrations/RabbitMqConnectionFactory.cs | 17 ++++++----- .../Integrations/RabbitMqMessage.cs | 29 +++++++++++++++---- .../Integrations/RabbitMqMessageFactory.cs | 12 ++++---- .../Integrations/RabbitMqPublisher.cs | 22 +++++++------- 11 files changed, 109 insertions(+), 65 deletions(-) diff --git a/EventFlow.sln b/EventFlow.sln index 554a301fc..3df186917 100644 --- a/EventFlow.sln +++ b/EventFlow.sln @@ -29,6 +29,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventFlow.MsSql", "Source\E EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventFlow.MsSql.Tests", "Source\EventFlow.MsSql.Tests\EventFlow.MsSql.Tests.csproj", "{CE19355C-6355-405F-A640-908AE4F83C2C}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "RabbitMQ", "RabbitMQ", "{ADA0FEA0-106C-47B6-AFFF-7A055FD068AC}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventFlow.RabbitMQ", "Source\EventFlow.RabbitMQ\EventFlow.RabbitMQ.csproj", "{E6AB068A-4B32-416D-AEF7-C347942E441F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventFlow.RabbitMQ.Tests", "Source\EventFlow.RabbitMQ.Tests\EventFlow.RabbitMQ.Tests.csproj", "{695DD7E9-5AEB-4CC6-A477-6F9AA5AD2255}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -71,6 +77,14 @@ Global {CE19355C-6355-405F-A640-908AE4F83C2C}.Debug|Any CPU.Build.0 = Debug|Any CPU {CE19355C-6355-405F-A640-908AE4F83C2C}.Release|Any CPU.ActiveCfg = Release|Any CPU {CE19355C-6355-405F-A640-908AE4F83C2C}.Release|Any CPU.Build.0 = Release|Any CPU + {E6AB068A-4B32-416D-AEF7-C347942E441F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E6AB068A-4B32-416D-AEF7-C347942E441F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E6AB068A-4B32-416D-AEF7-C347942E441F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E6AB068A-4B32-416D-AEF7-C347942E441F}.Release|Any CPU.Build.0 = Release|Any CPU + {695DD7E9-5AEB-4CC6-A477-6F9AA5AD2255}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {695DD7E9-5AEB-4CC6-A477-6F9AA5AD2255}.Debug|Any CPU.Build.0 = Debug|Any CPU + {695DD7E9-5AEB-4CC6-A477-6F9AA5AD2255}.Release|Any CPU.ActiveCfg = Release|Any CPU + {695DD7E9-5AEB-4CC6-A477-6F9AA5AD2255}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -84,6 +98,9 @@ Global {983EFD08-2256-4361-A869-23EB872328CB} = {88359036-4F35-487C-BF2C-4F31C7BC92D8} {96A39EA3-6772-409E-AF0B-C5A35A1A13CC} = {88359036-4F35-487C-BF2C-4F31C7BC92D8} {CE19355C-6355-405F-A640-908AE4F83C2C} = {88359036-4F35-487C-BF2C-4F31C7BC92D8} + {ADA0FEA0-106C-47B6-AFFF-7A055FD068AC} = {5EE323DE-E69B-451A-8AC3-22DD6A004FBA} + {E6AB068A-4B32-416D-AEF7-C347942E441F} = {ADA0FEA0-106C-47B6-AFFF-7A055FD068AC} + {695DD7E9-5AEB-4CC6-A477-6F9AA5AD2255} = {ADA0FEA0-106C-47B6-AFFF-7A055FD068AC} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {17607E2C-4E8E-45A2-85BD-0A5808E1C0F3} diff --git a/Source/EventFlow.RabbitMQ.Tests/EventFlow.RabbitMQ.Tests.csproj b/Source/EventFlow.RabbitMQ.Tests/EventFlow.RabbitMQ.Tests.csproj index eee3089bf..8f9105bfc 100644 --- a/Source/EventFlow.RabbitMQ.Tests/EventFlow.RabbitMQ.Tests.csproj +++ b/Source/EventFlow.RabbitMQ.Tests/EventFlow.RabbitMQ.Tests.csproj @@ -1,14 +1,14 @@  - netcoreapp3.1 + netcoreapp2.1;netcoreapp3.1 True False False - + diff --git a/Source/EventFlow.RabbitMQ.Tests/Integration/RabbitMqTests.cs b/Source/EventFlow.RabbitMQ.Tests/Integration/RabbitMqTests.cs index 7c10b140b..78fb4e7d6 100644 --- a/Source/EventFlow.RabbitMQ.Tests/Integration/RabbitMqTests.cs +++ b/Source/EventFlow.RabbitMQ.Tests/Integration/RabbitMqTests.cs @@ -27,10 +27,8 @@ using System.Threading; using System.Threading.Tasks; using EventFlow.Aggregates; -using EventFlow.Configuration; using EventFlow.EventStores; using EventFlow.Extensions; -using EventFlow.Logs; using EventFlow.RabbitMQ.Extensions; using EventFlow.RabbitMQ.Integrations; using EventFlow.TestHelpers; @@ -40,6 +38,8 @@ using EventFlow.TestHelpers.Aggregates.Queries; using EventFlow.TestHelpers.Aggregates.ValueObjects; using FluentAssertions; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using NUnit.Framework; namespace EventFlow.RabbitMQ.Tests.Integration @@ -74,10 +74,10 @@ public async Task Scenario() { var exchange = new Exchange($"eventflow-{Guid.NewGuid():N}"); using (var consumer = new RabbitMqConsumer(_uri, exchange, new[] { "#" })) - using (var resolver = BuildResolver(exchange)) + using (var serviceProvider = BuildServiceProvider(exchange)) { - var commandBus = resolver.Resolve(); - var eventJsonSerializer = resolver.Resolve(); + var commandBus = serviceProvider.GetRequiredService(); + var eventJsonSerializer = serviceProvider.GetRequiredService(); var pingId = PingId.New; await commandBus.PublishAsync(new ThingyPingCommand(ThingyId.New, pingId), _timeout.Token).ConfigureAwait(false); @@ -105,9 +105,9 @@ public async Task PublisherPerformance() const int totalMessageCount = taskCount * messagesPrThread; using (var consumer = new RabbitMqConsumer(_uri, exchange, new[] { "#" })) - using (var resolver = BuildResolver(exchange, o => o.RegisterServices(sr => sr.Register()))) + using (var resolver = BuildServiceProvider(exchange)) { - var rabbitMqPublisher = resolver.Resolve(); + var rabbitMqPublisher = resolver.GetRequiredService(); var tasks = Enumerable.Range(0, taskCount) .Select(i => Task.Run(() => SendMessagesAsync(rabbitMqPublisher, messagesPrThread, exchange, routingKey, exceptions, _timeout.Token))); @@ -147,16 +147,18 @@ private static async Task SendMessagesAsync( exceptions.Add(e); } } - - private IRootResolver BuildResolver(Exchange exchange, Func configure = null) + + private ServiceProvider BuildServiceProvider( + Exchange exchange, + Func configure = null) { configure = configure ?? (e => e); - return configure(EventFlowOptions.New + return configure(EventFlowOptions.New() .PublishToRabbitMq(RabbitMqConfiguration.With(_uri, false, exchange: exchange.Value)) .AddDefaults(EventFlowTestHelpers.Assembly)) - .RegisterServices(sr => sr.Register(Lifetime.Scoped)) - .CreateResolver(false); + .RegisterServices(sr => sr.TryAddScoped()) + .ServiceCollection.BuildServiceProvider(true); } } } diff --git a/Source/EventFlow.RabbitMQ.Tests/UnitTests/Integrations/RabbitMqPublisherTests.cs b/Source/EventFlow.RabbitMQ.Tests/UnitTests/Integrations/RabbitMqPublisherTests.cs index 4800e201b..d31cee8b2 100644 --- a/Source/EventFlow.RabbitMQ.Tests/UnitTests/Integrations/RabbitMqPublisherTests.cs +++ b/Source/EventFlow.RabbitMQ.Tests/UnitTests/Integrations/RabbitMqPublisherTests.cs @@ -26,10 +26,10 @@ using System.Threading; using System.Threading.Tasks; using EventFlow.Core; -using EventFlow.Logs; using EventFlow.RabbitMQ.Integrations; using EventFlow.TestHelpers; using AutoFixture; +using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; using RabbitMQ.Client; @@ -41,7 +41,7 @@ public class RabbitMqPublisherTests : TestsFor { private Mock _rabbitMqConnectionFactoryMock; private Mock _rabbitMqConfigurationMock; - private Mock _logMock; + private Mock>> _logMock; private Mock _modelMock; private Mock _rabbitConnectionMock; @@ -50,7 +50,7 @@ public void SetUp() { _rabbitMqConnectionFactoryMock = InjectMock(); _rabbitMqConfigurationMock = InjectMock(); - _logMock = InjectMock(); + _logMock = InjectMock>>(); Fixture.Inject>(new TransientFaultHandler( _logMock.Object, diff --git a/Source/EventFlow.RabbitMQ/EventFlow.RabbitMQ.csproj b/Source/EventFlow.RabbitMQ/EventFlow.RabbitMQ.csproj index ab39cf5be..0d87da65e 100644 --- a/Source/EventFlow.RabbitMQ/EventFlow.RabbitMQ.csproj +++ b/Source/EventFlow.RabbitMQ/EventFlow.RabbitMQ.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + netstandard2.0;netcoreapp2.1;netcoreapp3.1 True True False @@ -26,6 +26,6 @@ - + \ No newline at end of file diff --git a/Source/EventFlow.RabbitMQ/Extensions/EventFlowOptionsRabbitMqExtensions.cs b/Source/EventFlow.RabbitMQ/Extensions/EventFlowOptionsRabbitMqExtensions.cs index 7efcad7b1..07d709032 100644 --- a/Source/EventFlow.RabbitMQ/Extensions/EventFlowOptionsRabbitMqExtensions.cs +++ b/Source/EventFlow.RabbitMQ/Extensions/EventFlowOptionsRabbitMqExtensions.cs @@ -21,9 +21,10 @@ // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -using EventFlow.Configuration; +using EventFlow.Extensions; using EventFlow.RabbitMQ.Integrations; using EventFlow.Subscribers; +using Microsoft.Extensions.DependencyInjection.Extensions; namespace EventFlow.RabbitMQ.Extensions { @@ -35,14 +36,12 @@ public static IEventFlowOptions PublishToRabbitMq( { return eventFlowOptions.RegisterServices(sr => { - sr.Register(Lifetime.Singleton); - sr.Register(Lifetime.Singleton); - sr.Register(Lifetime.Singleton); - sr.Register(Lifetime.Singleton); - - sr.Register(rc => configuration, Lifetime.Singleton); - - sr.Register(); + sr.TryAddSingleton(); + sr.TryAddSingleton(); + sr.TryAddSingleton(); + sr.TryAddSingleton(); + sr.TryAddSingleton(rc => configuration); + sr.TryAddTransient(); }); } } diff --git a/Source/EventFlow.RabbitMQ/Integrations/RabbitConnection.cs b/Source/EventFlow.RabbitMQ/Integrations/RabbitConnection.cs index aa9c11800..0dbdd0e51 100644 --- a/Source/EventFlow.RabbitMQ/Integrations/RabbitConnection.cs +++ b/Source/EventFlow.RabbitMQ/Integrations/RabbitConnection.cs @@ -28,22 +28,25 @@ using System.Threading.Tasks; using EventFlow.Core; using EventFlow.Extensions; -using EventFlow.Logs; +using Microsoft.Extensions.Logging; using RabbitMQ.Client; namespace EventFlow.RabbitMQ.Integrations { public class RabbitConnection : IRabbitConnection { - private readonly ILog _log; + private readonly ILogger _logger; private readonly IConnection _connection; private readonly AsyncLock _asyncLock; private readonly ConcurrentBag _models; - public RabbitConnection(ILog log, int maxModels, IConnection connection) + public RabbitConnection( + ILogger logger, + int maxModels, + IConnection connection) { + _logger = logger; _connection = connection; - _log = log; _asyncLock = new AsyncLock(maxModels); _models = new ConcurrentBag(Enumerable.Range(0, maxModels).Select(_ => connection.CreateModel())); } @@ -52,8 +55,7 @@ public async Task WithModelAsync(Func action, CancellationTok { using (await _asyncLock.WaitAsync(cancellationToken).ConfigureAwait(false)) { - IModel model; - if (!_models.TryTake(out model)) + if (!_models.TryTake(out var model)) { throw new InvalidOperationException( "This should NEVER happen! If it does, please report a bug."); @@ -74,12 +76,12 @@ public async Task WithModelAsync(Func action, CancellationTok public void Dispose() { + _logger.LogTrace("Disposing RabbitMQ connection"); foreach (var model in _models) { - model.DisposeSafe(_log, "Failed to dispose model"); + model.DisposeSafe(_logger, "Failed to dispose model"); } - _connection.DisposeSafe(_log, "Failed to dispose connection"); - _log.Verbose("Disposing RabbitMQ connection"); + _connection.DisposeSafe(_logger, "Failed to dispose connection"); } } } \ No newline at end of file diff --git a/Source/EventFlow.RabbitMQ/Integrations/RabbitMqConnectionFactory.cs b/Source/EventFlow.RabbitMQ/Integrations/RabbitMqConnectionFactory.cs index 533644b4c..99dca051b 100644 --- a/Source/EventFlow.RabbitMQ/Integrations/RabbitMqConnectionFactory.cs +++ b/Source/EventFlow.RabbitMQ/Integrations/RabbitMqConnectionFactory.cs @@ -27,23 +27,23 @@ using System.Threading; using System.Threading.Tasks; using EventFlow.Core; -using EventFlow.Logs; +using Microsoft.Extensions.Logging; using RabbitMQ.Client; namespace EventFlow.RabbitMQ.Integrations { public class RabbitMqConnectionFactory : IRabbitMqConnectionFactory { - private readonly ILog _log; + private readonly ILogger _logger; private readonly IRabbitMqConfiguration _configuration; private readonly AsyncLock _asyncLock = new AsyncLock(); private readonly Dictionary _connectionFactories = new Dictionary(); public RabbitMqConnectionFactory( - ILog log, + ILogger logger, IRabbitMqConfiguration configuration) { - _log = log; + _logger = logger; _configuration = configuration; } @@ -52,19 +52,20 @@ public async Task CreateConnectionAsync(Uri uri, Cancellation var connectionFactory = await CreateConnectionFactoryAsync(uri, cancellationToken).ConfigureAwait(false); var connection = connectionFactory.CreateConnection(); - return new RabbitConnection(_log, _configuration.ModelsPrConnection, connection); + return new RabbitConnection(_logger, _configuration.ModelsPrConnection, connection); } private async Task CreateConnectionFactoryAsync(Uri uri, CancellationToken cancellationToken) { using (await _asyncLock.WaitAsync(cancellationToken).ConfigureAwait(false)) { - ConnectionFactory connectionFactory; - if (_connectionFactories.TryGetValue(uri, out connectionFactory)) + if (_connectionFactories.TryGetValue(uri, out var connectionFactory)) { return connectionFactory; } - _log.Verbose("Creating RabbitMQ connection factory to {0}", uri.Host); + _logger.LogTrace( + "Creating RabbitMQ connection factory to {RabbitMqHost}", + uri.Host); connectionFactory = new ConnectionFactory { diff --git a/Source/EventFlow.RabbitMQ/Integrations/RabbitMqMessage.cs b/Source/EventFlow.RabbitMQ/Integrations/RabbitMqMessage.cs index 0c5cdfd2b..3fbcb63b5 100644 --- a/Source/EventFlow.RabbitMQ/Integrations/RabbitMqMessage.cs +++ b/Source/EventFlow.RabbitMQ/Integrations/RabbitMqMessage.cs @@ -41,11 +41,30 @@ public RabbitMqMessage( RoutingKey routingKey, MessageId messageId) { - if (string.IsNullOrEmpty(message)) throw new ArgumentNullException(nameof(message)); - if (headers == null) throw new ArgumentNullException(nameof(headers)); - if (exchange == null) throw new ArgumentNullException(nameof(exchange)); - if (routingKey == null) throw new ArgumentNullException(nameof(routingKey)); - if (messageId == null) throw new ArgumentNullException(nameof(messageId)); + if (string.IsNullOrEmpty(message)) + { + throw new ArgumentNullException(nameof(message)); + } + + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } + + if (exchange == null) + { + throw new ArgumentNullException(nameof(exchange)); + } + + if (routingKey == null) + { + throw new ArgumentNullException(nameof(routingKey)); + } + + if (messageId == null) + { + throw new ArgumentNullException(nameof(messageId)); + } Message = message; Headers = headers; diff --git a/Source/EventFlow.RabbitMQ/Integrations/RabbitMqMessageFactory.cs b/Source/EventFlow.RabbitMQ/Integrations/RabbitMqMessageFactory.cs index ce1973e61..d73381bc2 100644 --- a/Source/EventFlow.RabbitMQ/Integrations/RabbitMqMessageFactory.cs +++ b/Source/EventFlow.RabbitMQ/Integrations/RabbitMqMessageFactory.cs @@ -24,22 +24,22 @@ using EventFlow.Aggregates; using EventFlow.EventStores; using EventFlow.Extensions; -using EventFlow.Logs; +using Microsoft.Extensions.Logging; namespace EventFlow.RabbitMQ.Integrations { public class RabbitMqMessageFactory : IRabbitMqMessageFactory { - private readonly ILog _log; + private readonly ILogger _logger; private readonly IEventJsonSerializer _eventJsonSerializer; private readonly IRabbitMqConfiguration _rabbitMqConfiguration; public RabbitMqMessageFactory( - ILog log, + ILogger logger, IEventJsonSerializer eventJsonSerializer, IRabbitMqConfiguration rabbitMqConfiguration) { - _log = log; + _logger = logger; _eventJsonSerializer = eventJsonSerializer; _rabbitMqConfiguration = rabbitMqConfiguration; } @@ -64,7 +64,9 @@ public RabbitMqMessage CreateMessage(IDomainEvent domainEvent) routingKey, new MessageId(domainEvent.Metadata[MetadataKeys.EventId])); - _log.Verbose("Create RabbitMQ message {0}", rabbitMqMessage); + _logger.LogTrace( + "Create RabbitMQ message {Message}", + rabbitMqMessage.ToString()); return rabbitMqMessage; } diff --git a/Source/EventFlow.RabbitMQ/Integrations/RabbitMqPublisher.cs b/Source/EventFlow.RabbitMQ/Integrations/RabbitMqPublisher.cs index 763353a3c..75ef0d00c 100644 --- a/Source/EventFlow.RabbitMQ/Integrations/RabbitMqPublisher.cs +++ b/Source/EventFlow.RabbitMQ/Integrations/RabbitMqPublisher.cs @@ -29,14 +29,14 @@ using System.Threading.Tasks; using EventFlow.Core; using EventFlow.Extensions; -using EventFlow.Logs; +using Microsoft.Extensions.Logging; using RabbitMQ.Client; namespace EventFlow.RabbitMQ.Integrations { public class RabbitMqPublisher : IDisposable, IRabbitMqPublisher { - private readonly ILog _log; + private readonly ILogger _logger; private readonly IRabbitMqConnectionFactory _connectionFactory; private readonly IRabbitMqConfiguration _configuration; private readonly ITransientFaultHandler _transientFaultHandler; @@ -44,12 +44,12 @@ public class RabbitMqPublisher : IDisposable, IRabbitMqPublisher private readonly Dictionary _connections = new Dictionary(); public RabbitMqPublisher( - ILog log, + ILogger logger, IRabbitMqConnectionFactory connectionFactory, IRabbitMqConfiguration configuration, ITransientFaultHandler transientFaultHandler) { - _log = log; + _logger = logger; _connectionFactory = connectionFactory; _configuration = configuration; _transientFaultHandler = transientFaultHandler; @@ -88,7 +88,7 @@ await _transientFaultHandler.TryAsync( _connections.Remove(uri); } } - _log.Error(e, "Failed to publish domain events to RabbitMQ"); + _logger.LogError(e, "Failed to publish domain events to RabbitMQ"); throw; } } @@ -97,8 +97,7 @@ private async Task GetRabbitMqConnectionAsync(Uri uri, Cancel { using (await _asyncLock.WaitAsync(cancellationToken).ConfigureAwait(false)) { - IRabbitConnection rabbitConnection; - if (_connections.TryGetValue(uri, out rabbitConnection)) + if (_connections.TryGetValue(uri, out var rabbitConnection)) { return rabbitConnection; } @@ -114,8 +113,8 @@ private Task PublishAsync( IModel model, IReadOnlyCollection messages) { - _log.Verbose( - "Publishing {0} domain events to RabbitMQ host '{1}'", + _logger.LogTrace( + "Publishing {EventCount} domain events to RabbitMQ host {RabbitMqHost}", messages.Count, _configuration.Uri.Host); @@ -136,7 +135,10 @@ private Task PublishAsync( return Task.FromResult(0); } - protected virtual void PublishSingleMessage(IModel model, RabbitMqMessage message, byte[] bytes, IBasicProperties basicProperties) + protected virtual void PublishSingleMessage( + IModel model, + RabbitMqMessage message, byte[] bytes, + IBasicProperties basicProperties) { // TODO: Evil or not evil? Do a Task.Run here? model.BasicPublish(message.Exchange.Value, message.RoutingKey.Value, false, basicProperties, bytes); From 10f0da8b011eb39832e9d9256aac586336694e77 Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Sat, 12 Jun 2021 10:11:59 +0200 Subject: [PATCH 2/4] Update README --- EventFlow.sln | 7 +++++++ README.md | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/EventFlow.sln b/EventFlow.sln index 3df186917..89ab0ddc6 100644 --- a/EventFlow.sln +++ b/EventFlow.sln @@ -35,6 +35,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventFlow.RabbitMQ", "Sourc EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventFlow.RabbitMQ.Tests", "Source\EventFlow.RabbitMQ.Tests\EventFlow.RabbitMQ.Tests.csproj", "{695DD7E9-5AEB-4CC6-A477-6F9AA5AD2255}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".general", ".general", "{A920B8BC-D459-45F8-9E78-FF209946DB99}" + ProjectSection(SolutionItems) = preProject + MIGRATION_GUIDE.md = MIGRATION_GUIDE.md + README.md = README.md + RELEASE_NOTES.md = RELEASE_NOTES.md + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/README.md b/README.md index 870b7afa9..f7c2d8c63 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ The following list key characteristics of each version as well as its related br - 🟢 `EventFlow.MsSql` - 💀 `EventFlow.Owin` - 🔴 `EventFlow.PostgreSql` - - 🔴 `EventFlow.RabbitMQ` + - 🟢 `EventFlow.RabbitMQ` - 🟢 `EventFlow.Sql` - 🔴 `EventFlow.SQLite` - 🔴 `EventFlow.TestHelpers` From 205659c51318e49845782025cb190899bbc39dfd Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Sat, 12 Jun 2021 10:21:07 +0200 Subject: [PATCH 3/4] Lets just default to localhost instead of bothering developers --- Source/EventFlow.RabbitMQ.Tests/Integration/RabbitMqTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/EventFlow.RabbitMQ.Tests/Integration/RabbitMqTests.cs b/Source/EventFlow.RabbitMQ.Tests/Integration/RabbitMqTests.cs index 78fb4e7d6..9cca92fc3 100644 --- a/Source/EventFlow.RabbitMQ.Tests/Integration/RabbitMqTests.cs +++ b/Source/EventFlow.RabbitMQ.Tests/Integration/RabbitMqTests.cs @@ -56,7 +56,7 @@ public void SetUp() var url = Environment.GetEnvironmentVariable("RABBITMQ_URL"); if (string.IsNullOrEmpty(url)) { - Assert.Inconclusive("The environment variable named 'RABBITMQ_URL' isn't set. Set it to e.g. 'amqp://localhost'"); + url = "amqp://localhost"; } _uri = new Uri(url); From 5990d308fe4814ecf32365c5ba539b6431ab4668 Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Sat, 12 Jun 2021 19:27:02 +0200 Subject: [PATCH 4/4] Scope oit --- .../Integration/RabbitMqTests.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Source/EventFlow.RabbitMQ.Tests/Integration/RabbitMqTests.cs b/Source/EventFlow.RabbitMQ.Tests/Integration/RabbitMqTests.cs index 9cca92fc3..20b20abbd 100644 --- a/Source/EventFlow.RabbitMQ.Tests/Integration/RabbitMqTests.cs +++ b/Source/EventFlow.RabbitMQ.Tests/Integration/RabbitMqTests.cs @@ -74,10 +74,11 @@ public async Task Scenario() { var exchange = new Exchange($"eventflow-{Guid.NewGuid():N}"); using (var consumer = new RabbitMqConsumer(_uri, exchange, new[] { "#" })) - using (var serviceProvider = BuildServiceProvider(exchange)) + using (var rootServiceProvider = BuildServiceProvider(exchange)) + using (var serviceScope = rootServiceProvider.CreateScope()) { - var commandBus = serviceProvider.GetRequiredService(); - var eventJsonSerializer = serviceProvider.GetRequiredService(); + var commandBus = serviceScope.ServiceProvider.GetRequiredService(); + var eventJsonSerializer = serviceScope.ServiceProvider.GetRequiredService(); var pingId = PingId.New; await commandBus.PublishAsync(new ThingyPingCommand(ThingyId.New, pingId), _timeout.Token).ConfigureAwait(false); @@ -105,9 +106,10 @@ public async Task PublisherPerformance() const int totalMessageCount = taskCount * messagesPrThread; using (var consumer = new RabbitMqConsumer(_uri, exchange, new[] { "#" })) - using (var resolver = BuildServiceProvider(exchange)) + using (var rootServiceProvider = BuildServiceProvider(exchange)) + using (var serviceScope = rootServiceProvider.CreateScope()) { - var rabbitMqPublisher = resolver.GetRequiredService(); + var rabbitMqPublisher = serviceScope.ServiceProvider.GetRequiredService(); var tasks = Enumerable.Range(0, taskCount) .Select(i => Task.Run(() => SendMessagesAsync(rabbitMqPublisher, messagesPrThread, exchange, routingKey, exceptions, _timeout.Token)));