Skip to content

Commit

Permalink
chore: Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
alex289 committed Nov 21, 2024
1 parent 693ca45 commit 7a166d1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static RabbitMqConfiguration GetRabbitMqConfiguration(
Port = int.Parse(rabbitPort ?? "0"),
Enabled = bool.Parse(rabbitEnabled ?? "false"),
Username = rabbitUser ?? "",
Password = rabbitPass ?? "",
Password = rabbitPass ?? ""
};
}
}
7 changes: 5 additions & 2 deletions CleanArchitecture.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
var isAspire = builder.Configuration["ASPIRE_ENABLED"] == "true";

var rabbitConfiguration = builder.Configuration.GetRabbitMqConfiguration();
var redisConnectionString = isAspire ? builder.Configuration["ConnectionStrings:Redis"] : builder.Configuration["RedisHostName"];
var dbConnectionString = isAspire ? builder.Configuration["ConnectionStrings:Database"] : builder.Configuration["ConnectionStrings:DefaultConnection"];
var redisConnectionString =
isAspire ? builder.Configuration["ConnectionStrings:Redis"] : builder.Configuration["RedisHostName"];
var dbConnectionString = isAspire
? builder.Configuration["ConnectionStrings:Database"]
: builder.Configuration["ConnectionStrings:DefaultConnection"];

if (builder.Environment.IsProduction())
{
Expand Down
4 changes: 2 additions & 2 deletions CleanArchitecture.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var redis = builder.AddRedis("Redis");

var rabbitPasswordRessource = new ParameterResource("password", _ => "guest");
var rabbitPasswordParameter =
var rabbitPasswordParameter =
builder.AddParameter("username", rabbitPasswordRessource.Value);

var rabbitMq = builder
Expand All @@ -22,4 +22,4 @@
.WithReference(db)
.WaitFor(sqlServer);

builder.Build().Run();
builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace CleanArchitecture.Domain.Rabbitmq.Extensions;
Expand Down
9 changes: 5 additions & 4 deletions CleanArchitecture.Domain/Rabbitmq/RabbitMqHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ namespace CleanArchitecture.Domain.Rabbitmq;

public sealed class RabbitMqHandler : BackgroundService
{
private IChannel? _channel;
private readonly RabbitMqConfiguration _configuration;

private readonly ConcurrentDictionary<string, List<ConsumeEventHandler>> _consumers = new();

private readonly ILogger<RabbitMqHandler> _logger;

private readonly ConcurrentQueue<IRabbitMqAction> _pendingActions = new();
private IChannel? _channel;

public RabbitMqHandler(
RabbitMqConfiguration configuration,
Expand All @@ -46,7 +46,7 @@ public override async Task StartAsync(CancellationToken cancellationToken)
HostName = _configuration.Host,
Port = _configuration.Port,
UserName = _configuration.Username,
Password = _configuration.Password,
Password = _configuration.Password
};

var connection = await factory.CreateConnectionAsync(cancellationToken);
Expand Down Expand Up @@ -133,14 +133,15 @@ public void AddExchangeConsumer(string exchange, string queue, ConsumeEventHandl
AddExchangeConsumer(exchange, string.Empty, queue, consumer);
}

private async Task AddEventConsumer(string exchange, string queueName, string routingKey, ConsumeEventHandler consumer)
private async Task AddEventConsumer(string exchange, string queueName, string routingKey,
ConsumeEventHandler consumer)
{
if (!_configuration.Enabled)
{
_logger.LogInformation("RabbitMQ is disabled. Event consumer will not be added.");
return;
}

var key = $"{exchange}-{routingKey}";

if (!_consumers.TryGetValue(key, out var consumers))
Expand Down
10 changes: 4 additions & 6 deletions CleanArchitecture.ServiceDefaults/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ public static void AddServiceDefaults<TBuilder>(this TBuilder builder) where TBu
http.AddServiceDiscovery();
});

builder.Services.Configure<ServiceDiscoveryOptions>(options =>
{
options.AllowedSchemes = ["https"];
});
builder.Services.Configure<ServiceDiscoveryOptions>(options => { options.AllowedSchemes = ["https"]; });
}

private static void ConfigureOpenTelemetry<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
Expand Down Expand Up @@ -67,7 +64,8 @@ private static void ConfigureOpenTelemetry<TBuilder>(this TBuilder builder) wher
builder.AddOpenTelemetryExporters();
}

private static void AddOpenTelemetryExporters<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
private static void AddOpenTelemetryExporters<TBuilder>(this TBuilder builder)
where TBuilder : IHostApplicationBuilder
{
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);

Expand Down Expand Up @@ -100,4 +98,4 @@ public static void MapDefaultEndpoints(this WebApplication app)
});
}
}
}
}

0 comments on commit 7a166d1

Please sign in to comment.