Open
Conversation
Gwymlas
requested changes
Mar 19, 2026
Gwymlas
left a comment
There was a problem hiding this comment.
Исправить лабораторную работу, сейчас балансировщик никак не участвует
|
|
||
| namespace AspireApp.ApiGateway.LoadBalancing; | ||
|
|
||
| public class WeightedRandomLoadBalancer : ILoadBalancer |
Comment on lines
+23
to
+35
| public WeightedRandomLoadBalancer() | ||
| { | ||
| _servicesProvider = null!; | ||
| _weights = null!; | ||
| } | ||
|
|
||
| public WeightedRandomLoadBalancer( | ||
| Func<Task<List<Service>>> servicesProvider, | ||
| Dictionary<string, int> weights) : this() | ||
| { | ||
| _servicesProvider = servicesProvider; | ||
| _weights = weights; | ||
| } |
| private readonly Dictionary<string, int> _weights; | ||
| private readonly Random _random = new(); | ||
|
|
||
| public string Type => throw new NotImplementedException(); |
There was a problem hiding this comment.
Type должен совпадать с "Type" в ocelot
| public async Task<Response<ServiceHostAndPort>> LeaseAsync(HttpContext httpContext) | ||
| { | ||
| var services = await _servicesProvider(); | ||
| if (services == null || services.Count == 0) |
There was a problem hiding this comment.
Убрать лишнюю проверку services == null
Comment on lines
+71
to
+75
| public class ServicesAreEmptyError : Error | ||
| { | ||
| public ServicesAreEmptyError(string message) | ||
| : base(message, OcelotErrorCode.ServicesAreEmptyError, 503) { } | ||
| } |
There was a problem hiding this comment.
Добавить сюда cors и убрать из сервиса
AspireApp.AppHost/AppHost.cs
Outdated
Comment on lines
+5
to
+24
| var api0 = builder.AddProject<Projects.AspireApp_ApiService>("warehouse-api-0") | ||
| .WithReference(cache) | ||
| .WithEnvironment("REPLICA_ID", "0") | ||
| .WaitFor(cache); | ||
|
|
||
| var api1 = builder.AddProject<Projects.AspireApp_ApiService>("warehouse-api-1") | ||
| .WithReference(cache) | ||
| .WithEnvironment("REPLICA_ID", "1") | ||
| .WaitFor(cache); | ||
|
|
||
| var api2 = builder.AddProject<Projects.AspireApp_ApiService>("warehouse-api-2") | ||
| .WithReference(cache) | ||
| .WithEnvironment("REPLICA_ID", "2") | ||
| .WaitFor(cache); | ||
|
|
||
| var gateway = builder.AddProject("api-gateway", "../AspireApp.ApiGateway/AspireApp.ApiGateway.csproj") | ||
| .WithReference(api0) | ||
| .WithReference(api1) | ||
| .WithReference(api2) | ||
| .WaitFor(api0).WaitFor(api1).WaitFor(api2); |
AspireApp.AppHost/AppHost.cs
Outdated
Comment on lines
+10
to
+13
| var api1 = builder.AddProject<Projects.AspireApp_ApiService>("warehouse-api-1") | ||
| .WithReference(cache) | ||
| .WithEnvironment("REPLICA_ID", "1") | ||
| .WaitFor(cache); |
There was a problem hiding this comment.
Будут запущены не на тех портах, которые указаны в ocelot.json
AspireApp.AppHost/AppHost.cs
Outdated
Comment on lines
+27
to
+28
| .WithReference(gateway) | ||
| .WithEnvironment("BaseAddress", gateway.GetEndpoint("http")) |
There was a problem hiding this comment.
Не нужен, BaseAddress будет браться из appsettings
Client.Wasm/Program.cs
Outdated
Comment on lines
+20
to
+26
| var apiBaseUrl = builder.Configuration["BaseAddress"] | ||
| ?? throw new InvalidOperationException("BaseAddress not configured"); | ||
|
|
||
| builder.Services.AddHttpClient("ApiClient", client => | ||
| { | ||
| client.BaseAddress = new Uri(apiBaseUrl); | ||
| }); No newline at end of file |
There was a problem hiding this comment.
Вроде это дублирование кода выше
BaseAddress в appsettings остался прежним, то есть клиент обращается на один из запущенных сервисов в обход апи гейтвея
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ФИО: Карпачева Полина
Номер группы: 6512
Номер лабораторной: 2
Номер варианта: 22
Краткое описание предметной области: Товар на складе
Краткое описание добавленных фич: Добавлен Api Gateway, реплики