Skip to content

Commit

Permalink
Merge pull request #58 from mizrael/rabbit-vhost
Browse files Browse the repository at this point in the history
added virtual host
  • Loading branch information
mizrael authored Jan 3, 2022
2 parents e30e2e7 + 7b89ba7 commit feea93a
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,7 +7,6 @@
using RabbitMQ.Client;
using System;
using System.Collections.Generic;
using System.Security.Authentication;
using System.Threading.Tasks;
using Xunit;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/OpenSleigh.E2ETests/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"Rabbit": {
"Hostname": "127.0.0.1",
"VirtualHost": "/opensleigh",
"UserName": "guest",
"Password": "guest"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Extensions.Configuration;
using NSubstitute;
using RabbitMQ.Client;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -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));
}

/// <summary>
Expand All @@ -35,6 +37,7 @@ public IConnection Connect()
HostName = RabbitConfiguration.HostName,
UserName = RabbitConfiguration.UserName,
Password = RabbitConfiguration.Password,
VirtualHost = RabbitConfiguration.VirtualHost,
Port = AmqpTcpEndpoint.UseDefaultPort,
DispatchConsumersAsync = true
};
Expand Down
1 change: 1 addition & 0 deletions tests/OpenSleigh.Transport.RabbitMQ.Tests/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"Rabbit": {
"Hostname": "127.0.0.1",
"VirtualHost": "/opensleigh",
"UserName": "guest",
"Password": "guest"
},
Expand Down
2 changes: 1 addition & 1 deletion tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit feea93a

Please sign in to comment.