mirror of
https://github.com/alex289/CleanArchitecture.git
synced 2025-06-30 02:31:08 +00:00
fix: Use correct rabbit and redis connection
This commit is contained in:
parent
54062982d7
commit
55951f8ba1
@ -31,6 +31,7 @@ builder.Services
|
|||||||
if (builder.Environment.IsProduction())
|
if (builder.Environment.IsProduction())
|
||||||
{
|
{
|
||||||
var rabbitHost = builder.Configuration["RabbitMQ:Host"];
|
var rabbitHost = builder.Configuration["RabbitMQ:Host"];
|
||||||
|
var rabbitPort = builder.Configuration["RabbitMQ:Port"];
|
||||||
var rabbitUser = builder.Configuration["RabbitMQ:Username"];
|
var rabbitUser = builder.Configuration["RabbitMQ:Username"];
|
||||||
var rabbitPass = builder.Configuration["RabbitMQ:Password"];
|
var rabbitPass = builder.Configuration["RabbitMQ:Password"];
|
||||||
|
|
||||||
@ -39,7 +40,7 @@ if (builder.Environment.IsProduction())
|
|||||||
.AddSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")!)
|
.AddSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")!)
|
||||||
.AddRedis(builder.Configuration["RedisHostName"]!, "Redis")
|
.AddRedis(builder.Configuration["RedisHostName"]!, "Redis")
|
||||||
.AddRabbitMQ(
|
.AddRabbitMQ(
|
||||||
$"amqp://{rabbitUser}:{rabbitPass}@{rabbitHost}",
|
$"amqp://{rabbitUser}:{rabbitPass}@{rabbitHost}:{rabbitPort}",
|
||||||
name: "RabbitMQ");
|
name: "RabbitMQ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
"RedisHostName": "",
|
"RedisHostName": "",
|
||||||
"RabbitMQ": {
|
"RabbitMQ": {
|
||||||
"Host": "localhost",
|
"Host": "localhost",
|
||||||
|
"Port": 5672,
|
||||||
"Username": "guest",
|
"Username": "guest",
|
||||||
"Password": "guest",
|
"Password": "guest",
|
||||||
"Enabled": "True"
|
"Enabled": "True"
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
"RedisHostName": "",
|
"RedisHostName": "",
|
||||||
"RabbitMQ": {
|
"RabbitMQ": {
|
||||||
"Host": "localhost",
|
"Host": "localhost",
|
||||||
|
"Port": 5672,
|
||||||
"Username": "guest",
|
"Username": "guest",
|
||||||
"Password": "guest",
|
"Password": "guest",
|
||||||
"Enabled": "True"
|
"Enabled": "True"
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
"RedisHostName": "redis",
|
"RedisHostName": "redis",
|
||||||
"RabbitMQ": {
|
"RabbitMQ": {
|
||||||
"Host": "rabbitmq",
|
"Host": "rabbitmq",
|
||||||
|
"Port": 5672,
|
||||||
"Username": "admin",
|
"Username": "admin",
|
||||||
"Password": "DOIA9234JF",
|
"Password": "DOIA9234JF",
|
||||||
"Enabled": "True"
|
"Enabled": "True"
|
||||||
|
@ -3,6 +3,7 @@ namespace CleanArchitecture.Domain.Rabbitmq;
|
|||||||
public sealed class RabbitMqConfiguration
|
public sealed class RabbitMqConfiguration
|
||||||
{
|
{
|
||||||
public string Host { get; set; } = string.Empty;
|
public string Host { get; set; } = string.Empty;
|
||||||
|
public int Port { get; set; }
|
||||||
public bool Enabled { get; set; }
|
public bool Enabled { get; set; }
|
||||||
public string Username { get; set; } = string.Empty;
|
public string Username { get; set; } = string.Empty;
|
||||||
public string Password { get; set; } = string.Empty;
|
public string Password { get; set; } = string.Empty;
|
||||||
|
@ -39,6 +39,7 @@ public sealed class RabbitMqHandler : BackgroundService
|
|||||||
{
|
{
|
||||||
AutomaticRecoveryEnabled = true,
|
AutomaticRecoveryEnabled = true,
|
||||||
HostName = configuration.Host,
|
HostName = configuration.Host,
|
||||||
|
Port = configuration.Port,
|
||||||
UserName = configuration.Username,
|
UserName = configuration.Username,
|
||||||
Password = configuration.Password,
|
Password = configuration.Password,
|
||||||
DispatchConsumersAsync = true
|
DispatchConsumersAsync = true
|
||||||
|
@ -4,5 +4,5 @@ public static class Configuration
|
|||||||
{
|
{
|
||||||
public const int RedisPort = 6379;
|
public const int RedisPort = 6379;
|
||||||
public const int MsSqlPort = 1433;
|
public const int MsSqlPort = 1433;
|
||||||
public const int RabbitMqPort = 5673;
|
public const int RabbitMqPort = 5672;
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@ internal class GlobalSetupFixture
|
|||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
public static RabbitMqContainer RabbitContainer { get; } = new RabbitMqBuilder()
|
public static RabbitMqContainer RabbitContainer { get; } = new RabbitMqBuilder()
|
||||||
|
.WithUsername("guest")
|
||||||
|
.WithPassword("guest")
|
||||||
.WithPortBinding(Configuration.RabbitMqPort, assignRandomHostPort: true)
|
.WithPortBinding(Configuration.RabbitMqPort, assignRandomHostPort: true)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using CleanArchitecture.Domain.Rabbitmq;
|
||||||
using CleanArchitecture.IntegrationTests.Constants;
|
using CleanArchitecture.IntegrationTests.Constants;
|
||||||
using CleanArchitecture.IntegrationTests.Infrastructure.Auth;
|
using CleanArchitecture.IntegrationTests.Infrastructure.Auth;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
@ -33,22 +34,27 @@ public sealed class CleanArchitectureWebApplicationFactory : WebApplicationFacto
|
|||||||
|
|
||||||
base.ConfigureWebHost(builder);
|
base.ConfigureWebHost(builder);
|
||||||
|
|
||||||
builder.ConfigureAppConfiguration(configuration =>
|
var configuration = new ConfigurationBuilder()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
builder.ConfigureAppConfiguration(configurationBuilder =>
|
||||||
{
|
{
|
||||||
var redisPort = GlobalSetupFixture.RedisContainer.GetMappedPublicPort(Configuration.RedisPort);
|
var redisPort = GlobalSetupFixture.RedisContainer.GetMappedPublicPort(Configuration.RedisPort);
|
||||||
var rabbitPort = GlobalSetupFixture.RabbitContainer.GetMappedPublicPort(Configuration.RabbitMqPort);
|
var rabbitPort = GlobalSetupFixture.RabbitContainer.GetMappedPublicPort(Configuration.RabbitMqPort);
|
||||||
|
|
||||||
configuration.AddInMemoryCollection([
|
configurationBuilder.AddInMemoryCollection([
|
||||||
new KeyValuePair<string, string?>(
|
new KeyValuePair<string, string?>(
|
||||||
"ConnectionStrings:DefaultConnection",
|
"ConnectionStrings:DefaultConnection",
|
||||||
GlobalSetupFixture.DatabaseConnectionString),
|
GlobalSetupFixture.DatabaseConnectionString),
|
||||||
new KeyValuePair<string, string?>(
|
new KeyValuePair<string, string?>(
|
||||||
"RedisStackExchange:RedisConfigString",
|
"RedisHostName",
|
||||||
$"localhost:{redisPort},abortConnect=true"),
|
$"localhost:{redisPort}"),
|
||||||
new KeyValuePair<string, string?>(
|
new KeyValuePair<string, string?>(
|
||||||
"RabbitMQ:Host",
|
"RabbitMQ:Port",
|
||||||
$"localhost:{rabbitPort}")
|
rabbitPort.ToString())
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
configuration = configurationBuilder.Build();
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.ConfigureServices(services =>
|
builder.ConfigureServices(services =>
|
||||||
@ -66,6 +72,19 @@ public sealed class CleanArchitectureWebApplicationFactory : WebApplicationFacto
|
|||||||
|
|
||||||
using var scope = sp.CreateScope();
|
using var scope = sp.CreateScope();
|
||||||
var scopedServices = scope.ServiceProvider;
|
var scopedServices = scope.ServiceProvider;
|
||||||
|
|
||||||
|
// Readd rabbitmq options to use the correct port
|
||||||
|
var rabbitMq = new RabbitMqConfiguration();
|
||||||
|
configuration.Bind("RabbitMQ", rabbitMq);
|
||||||
|
services.AddSingleton(rabbitMq);
|
||||||
|
|
||||||
|
// Readd IDistributedCache to replace the memory cache with redis
|
||||||
|
services.AddStackExchangeRedisCache(options =>
|
||||||
|
{
|
||||||
|
options.Configuration = configuration["RedisHostName"];
|
||||||
|
options.InstanceName = "clean-architecture";
|
||||||
|
});
|
||||||
|
|
||||||
_registerCustomServicesHandler?.Invoke(services, sp, scopedServices);
|
_registerCustomServicesHandler?.Invoke(services, sp, scopedServices);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user