diff --git a/src/OpenSleigh.Core/DependencyInjection/ServiceCollectionExtensions.cs b/src/OpenSleigh.Core/DependencyInjection/ServiceCollectionExtensions.cs index 91c1824a..796b657d 100644 --- a/src/OpenSleigh.Core/DependencyInjection/ServiceCollectionExtensions.cs +++ b/src/OpenSleigh.Core/DependencyInjection/ServiceCollectionExtensions.cs @@ -64,7 +64,7 @@ private static void RegisterAllMessages(ITypeResolver typeResolver) Console.WriteLine("preloading all message types..."); var messageType = typeof(IMessage); - + // Assemblies are lazy loaded so using AppDomain.GetAssemblies is not reliable. var currAssembly = Assembly.GetEntryAssembly(); var visited = new HashSet(); diff --git a/src/OpenSleigh.Transport.RabbitMQ/RabbitBusConfiguratorExtensions.cs b/src/OpenSleigh.Transport.RabbitMQ/RabbitBusConfiguratorExtensions.cs index 2cf2c9bf..af08bf65 100644 --- a/src/OpenSleigh.Transport.RabbitMQ/RabbitBusConfiguratorExtensions.cs +++ b/src/OpenSleigh.Transport.RabbitMQ/RabbitBusConfiguratorExtensions.cs @@ -11,19 +11,22 @@ namespace OpenSleigh.Transport.RabbitMQ public record RabbitConfiguration { public RabbitConfiguration(string hostName, string userName, string password) - : this(hostName, userName, password, TimeSpan.FromSeconds(30)) - { - } + : this(hostName, userName, password, TimeSpan.FromSeconds(30)) { } public RabbitConfiguration(string hostName, string userName, string password, TimeSpan retryDelay) + : this(hostName: hostName, vhost: null, userName: userName, password:password, retryDelay) { } + + public RabbitConfiguration(string hostName, string vhost, string userName, string password, TimeSpan retryDelay) { HostName = hostName; UserName = userName; Password = password; RetryDelay = retryDelay; + VirtualHost = vhost; } public string HostName { get; } + public string VirtualHost { get; } public string UserName { get; } public string Password { get; } @@ -54,6 +57,7 @@ public static IBusConfigurator UseRabbitMQTransport(this IBusConfigurator busCon var connectionFactory = new ConnectionFactory() { HostName = config.HostName, + VirtualHost = config.VirtualHost, UserName = config.UserName, Password = config.Password, Port = AmqpTcpEndpoint.UseDefaultPort, diff --git a/tests/OpenSleigh.E2ETests/MongoRabbit/MongoRabbitEventBroadcastingScenario.cs b/tests/OpenSleigh.E2ETests/MongoRabbit/MongoRabbitEventBroadcastingScenario.cs index 5796ffe1..d5fd43dc 100644 --- a/tests/OpenSleigh.E2ETests/MongoRabbit/MongoRabbitEventBroadcastingScenario.cs +++ b/tests/OpenSleigh.E2ETests/MongoRabbit/MongoRabbitEventBroadcastingScenario.cs @@ -1,4 +1,6 @@ -using OpenSleigh.Core.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; +using OpenSleigh.Core; +using OpenSleigh.Core.DependencyInjection; using OpenSleigh.Core.Tests.E2E; using OpenSleigh.Core.Tests.Sagas; using OpenSleigh.Persistence.Mongo; @@ -7,11 +9,7 @@ using RabbitMQ.Client; using System; using System.Collections.Generic; -using System.Security.Authentication; using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; -using MongoDB.Driver; -using OpenSleigh.Core; using Xunit; namespace OpenSleigh.E2ETests.MongoRabbit @@ -70,6 +68,7 @@ public async Task DisposeAsync() HostName = _rabbitFixture.RabbitConfiguration.HostName, UserName = _rabbitFixture.RabbitConfiguration.UserName, Password = _rabbitFixture.RabbitConfiguration.Password, + VirtualHost = _rabbitFixture.RabbitConfiguration.VirtualHost, Port = AmqpTcpEndpoint.UseDefaultPort, DispatchConsumersAsync = true }; diff --git a/tests/OpenSleigh.E2ETests/MongoRabbit/MongoRabbitParentChildScenario.cs b/tests/OpenSleigh.E2ETests/MongoRabbit/MongoRabbitParentChildScenario.cs index 38c1796a..40b1e9a6 100644 --- a/tests/OpenSleigh.E2ETests/MongoRabbit/MongoRabbitParentChildScenario.cs +++ b/tests/OpenSleigh.E2ETests/MongoRabbit/MongoRabbitParentChildScenario.cs @@ -1,5 +1,4 @@ -using MongoDB.Driver; -using OpenSleigh.Core.DependencyInjection; +using OpenSleigh.Core.DependencyInjection; using OpenSleigh.Core.Tests.E2E; using OpenSleigh.Core.Tests.Sagas; using OpenSleigh.Persistence.Mongo; @@ -8,7 +7,6 @@ using RabbitMQ.Client; using System; using System.Collections.Generic; -using System.Security.Authentication; using System.Threading.Tasks; using Xunit; @@ -89,6 +87,7 @@ public async Task DisposeAsync() { HostName = _rabbitFixture.RabbitConfiguration.HostName, UserName = _rabbitFixture.RabbitConfiguration.UserName, + VirtualHost = _rabbitFixture.RabbitConfiguration.VirtualHost, Password = _rabbitFixture.RabbitConfiguration.Password, Port = AmqpTcpEndpoint.UseDefaultPort, DispatchConsumersAsync = true diff --git a/tests/OpenSleigh.E2ETests/MongoRabbit/MongoRabbitSimpleSagaScenario.cs b/tests/OpenSleigh.E2ETests/MongoRabbit/MongoRabbitSimpleSagaScenario.cs index e8230c33..eb5e5321 100644 --- a/tests/OpenSleigh.E2ETests/MongoRabbit/MongoRabbitSimpleSagaScenario.cs +++ b/tests/OpenSleigh.E2ETests/MongoRabbit/MongoRabbitSimpleSagaScenario.cs @@ -7,11 +7,7 @@ using RabbitMQ.Client; using System; using System.Collections.Generic; -using System.Security.Authentication; using System.Threading.Tasks; -using FluentAssertions; -using Microsoft.Extensions.Azure; -using MongoDB.Driver; using Xunit; namespace OpenSleigh.E2ETests.MongoRabbit @@ -65,6 +61,7 @@ public async Task DisposeAsync() HostName = _rabbitFixture.RabbitConfiguration.HostName, UserName = _rabbitFixture.RabbitConfiguration.UserName, Password = _rabbitFixture.RabbitConfiguration.Password, + VirtualHost = _rabbitFixture.RabbitConfiguration.VirtualHost, Port = AmqpTcpEndpoint.UseDefaultPort, DispatchConsumersAsync = true }; diff --git a/tests/OpenSleigh.E2ETests/PostgreSQLRabbit/PostgreSQLEventBroadcastingScenario.cs b/tests/OpenSleigh.E2ETests/PostgreSQLRabbit/PostgreSQLEventBroadcastingScenario.cs index 1b094295..dcca0cc1 100644 --- a/tests/OpenSleigh.E2ETests/PostgreSQLRabbit/PostgreSQLEventBroadcastingScenario.cs +++ b/tests/OpenSleigh.E2ETests/PostgreSQLRabbit/PostgreSQLEventBroadcastingScenario.cs @@ -64,6 +64,7 @@ public async Task DisposeAsync() HostName = _rabbitFixture.RabbitConfiguration.HostName, UserName = _rabbitFixture.RabbitConfiguration.UserName, Password = _rabbitFixture.RabbitConfiguration.Password, + VirtualHost = _rabbitFixture.RabbitConfiguration.VirtualHost, Port = AmqpTcpEndpoint.UseDefaultPort, DispatchConsumersAsync = true }; diff --git a/tests/OpenSleigh.E2ETests/PostgreSQLRabbit/PostgreSQLParentChildScenario.cs b/tests/OpenSleigh.E2ETests/PostgreSQLRabbit/PostgreSQLParentChildScenario.cs index e8af0bc1..9243d4a1 100644 --- a/tests/OpenSleigh.E2ETests/PostgreSQLRabbit/PostgreSQLParentChildScenario.cs +++ b/tests/OpenSleigh.E2ETests/PostgreSQLRabbit/PostgreSQLParentChildScenario.cs @@ -84,6 +84,7 @@ public async Task DisposeAsync() HostName = _rabbitFixture.RabbitConfiguration.HostName, UserName = _rabbitFixture.RabbitConfiguration.UserName, Password = _rabbitFixture.RabbitConfiguration.Password, + VirtualHost = _rabbitFixture.RabbitConfiguration.VirtualHost, Port = AmqpTcpEndpoint.UseDefaultPort, DispatchConsumersAsync = true }; diff --git a/tests/OpenSleigh.E2ETests/PostgreSQLRabbit/PostgreSQLSimpleSagaScenario.cs b/tests/OpenSleigh.E2ETests/PostgreSQLRabbit/PostgreSQLSimpleSagaScenario.cs index 722c2a86..dfa5180f 100644 --- a/tests/OpenSleigh.E2ETests/PostgreSQLRabbit/PostgreSQLSimpleSagaScenario.cs +++ b/tests/OpenSleigh.E2ETests/PostgreSQLRabbit/PostgreSQLSimpleSagaScenario.cs @@ -57,6 +57,7 @@ public async Task DisposeAsync() HostName = _rabbitFixture.RabbitConfiguration.HostName, UserName = _rabbitFixture.RabbitConfiguration.UserName, Password = _rabbitFixture.RabbitConfiguration.Password, + VirtualHost = _rabbitFixture.RabbitConfiguration.VirtualHost, Port = AmqpTcpEndpoint.UseDefaultPort, DispatchConsumersAsync = true }; diff --git a/tests/OpenSleigh.E2ETests/SQLServerRabbit/SqlServerEventBroadcastingScenario.cs b/tests/OpenSleigh.E2ETests/SQLServerRabbit/SqlServerEventBroadcastingScenario.cs index cf837d10..cff013e9 100644 --- a/tests/OpenSleigh.E2ETests/SQLServerRabbit/SqlServerEventBroadcastingScenario.cs +++ b/tests/OpenSleigh.E2ETests/SQLServerRabbit/SqlServerEventBroadcastingScenario.cs @@ -64,6 +64,7 @@ public async Task DisposeAsync() HostName = _rabbitFixture.RabbitConfiguration.HostName, UserName = _rabbitFixture.RabbitConfiguration.UserName, Password = _rabbitFixture.RabbitConfiguration.Password, + VirtualHost = _rabbitFixture.RabbitConfiguration.VirtualHost, Port = AmqpTcpEndpoint.UseDefaultPort, DispatchConsumersAsync = true }; diff --git a/tests/OpenSleigh.E2ETests/SQLServerRabbit/SqlServerParentChildScenario.cs b/tests/OpenSleigh.E2ETests/SQLServerRabbit/SqlServerParentChildScenario.cs index 9d058f74..6812232d 100644 --- a/tests/OpenSleigh.E2ETests/SQLServerRabbit/SqlServerParentChildScenario.cs +++ b/tests/OpenSleigh.E2ETests/SQLServerRabbit/SqlServerParentChildScenario.cs @@ -84,6 +84,7 @@ public async Task DisposeAsync() HostName = _rabbitFixture.RabbitConfiguration.HostName, UserName = _rabbitFixture.RabbitConfiguration.UserName, Password = _rabbitFixture.RabbitConfiguration.Password, + VirtualHost = _rabbitFixture.RabbitConfiguration.VirtualHost, Port = AmqpTcpEndpoint.UseDefaultPort, DispatchConsumersAsync = true }; diff --git a/tests/OpenSleigh.E2ETests/SQLServerRabbit/SqlServerSimpleSagaScenario.cs b/tests/OpenSleigh.E2ETests/SQLServerRabbit/SqlServerSimpleSagaScenario.cs index 9c8f00ef..a6c5fbc5 100644 --- a/tests/OpenSleigh.E2ETests/SQLServerRabbit/SqlServerSimpleSagaScenario.cs +++ b/tests/OpenSleigh.E2ETests/SQLServerRabbit/SqlServerSimpleSagaScenario.cs @@ -56,6 +56,7 @@ public async Task DisposeAsync() { HostName = _rabbitFixture.RabbitConfiguration.HostName, UserName = _rabbitFixture.RabbitConfiguration.UserName, + VirtualHost = _rabbitFixture.RabbitConfiguration.VirtualHost, Password = _rabbitFixture.RabbitConfiguration.Password, Port = AmqpTcpEndpoint.UseDefaultPort, DispatchConsumersAsync = true diff --git a/tests/OpenSleigh.E2ETests/appsettings.json b/tests/OpenSleigh.E2ETests/appsettings.json index 5ebb9b98..749d880d 100644 --- a/tests/OpenSleigh.E2ETests/appsettings.json +++ b/tests/OpenSleigh.E2ETests/appsettings.json @@ -10,6 +10,7 @@ }, "Rabbit": { "Hostname": "127.0.0.1", + "VirtualHost": "/opensleigh", "UserName": "guest", "Password": "guest" }, diff --git a/tests/OpenSleigh.Transport.RabbitMQ.Tests/Fixtures/RabbitFixture.cs b/tests/OpenSleigh.Transport.RabbitMQ.Tests/Fixtures/RabbitFixture.cs index 3ae18a7b..8dca7d55 100644 --- a/tests/OpenSleigh.Transport.RabbitMQ.Tests/Fixtures/RabbitFixture.cs +++ b/tests/OpenSleigh.Transport.RabbitMQ.Tests/Fixtures/RabbitFixture.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Configuration; -using NSubstitute; using RabbitMQ.Client; using System.Collections.Generic; using System.Linq; @@ -20,9 +19,12 @@ public RabbitFixture() .Build(); var rabbitSection = configuration.GetSection("Rabbit"); - this.RabbitConfiguration = new RabbitConfiguration(rabbitSection["HostName"], + this.RabbitConfiguration = new RabbitConfiguration( + rabbitSection["HostName"], + rabbitSection["VirtualHost"], rabbitSection["UserName"], - rabbitSection["Password"]); + rabbitSection["Password"], + System.TimeSpan.FromSeconds(10)); } /// @@ -35,6 +37,7 @@ public IConnection Connect() HostName = RabbitConfiguration.HostName, UserName = RabbitConfiguration.UserName, Password = RabbitConfiguration.Password, + VirtualHost = RabbitConfiguration.VirtualHost, Port = AmqpTcpEndpoint.UseDefaultPort, DispatchConsumersAsync = true }; diff --git a/tests/OpenSleigh.Transport.RabbitMQ.Tests/appsettings.json b/tests/OpenSleigh.Transport.RabbitMQ.Tests/appsettings.json index b26147e8..f2873d1b 100644 --- a/tests/OpenSleigh.Transport.RabbitMQ.Tests/appsettings.json +++ b/tests/OpenSleigh.Transport.RabbitMQ.Tests/appsettings.json @@ -1,6 +1,7 @@ { "Rabbit": { "Hostname": "127.0.0.1", + "VirtualHost": "/opensleigh", "UserName": "guest", "Password": "guest" }, diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index db9ac369..ed2cc5a5 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -40,7 +40,7 @@ services: container_name: openSleigh.tests.infrastructure.rabbitmq restart: always environment: - RABBITMQ_DEFAULT_VHOST: "/" + RABBITMQ_DEFAULT_VHOST: "/opensleigh" ports: - "15671:15671" - "15672:15672"