diff --git a/tasks/ostrovskaya-sf/lab_3/README.md b/tasks/ostrovskaya-sf/lab_3/README.md index e69de29..f4f637c 100644 --- a/tasks/ostrovskaya-sf/lab_3/README.md +++ b/tasks/ostrovskaya-sf/lab_3/README.md @@ -0,0 +1,87 @@ +# Отчет по лабораторной работе №3 + +Выполнила студентка гр. ИСЭбд-41 Островская С. Ф. + +## REST API, Gateway и синхронный обмен между микросервисами + +## Создание микросервисов + +1. Создала первый микросервис - `dotnet new web -n worker-1` +2. Добавила решение - `dotnet new sln` +3. Связала решение и проект - `dotnet sln worker-1.sln add worker-1.csproj` +4. Для второго микросервиса выполнила пункты 1-3 +5. Добавила библиотеку Swagger и OpenAi - `dotnet add worker-1.csproj package Swashbuckle.AspNetCore` , `dotnet add worker-1.csproj package Microsoft.AspNetCore.OpenApi` +6. Запустила - `dotnet run` + +Скриншоты протестированных микросервисов: +![](pic/pic1.jpg) +![](pic/pic2.jpg) + +## Реализация синхронного обмена + +Код реализации синхронного обмена: + +```cs +//Файд Program.cs проекта worker-2 +app.MapGet("/Requests/", async () => +{ + var httpClient = new HttpClient(); + var secondWorkerResponse = await httpClient.GetStringAsync("http://worker-1:8080/"); + + return secondWorkerResponse.ToArray(); +}) +.WithName("GetRequests") +.WithOpenApi(); +``` + +## Реализация gateway при помощи nginx + +Добавил nginx.conf: + +```conf +server { + listen 8080; + listen [::]:8080; + server_name localhost; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } + + location /worker-1/ { + proxy_pass http://worker-1:8080/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Prefix /worker-1; + } + + location /worker-2/ { + proxy_pass http://worker-2:8080/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Prefix /worker-2; + } +} + +``` + +Результат, после выполнения команды `docker compose up`: + +Docker: + +![](pic/pic3.jpg) + +index.html на gateway-1: + +![](pic/pic4.jpg) + +worker-1: + +![](pic/pic5.jpg) + +worker-2: + +![](pic/pic6.jpg) \ No newline at end of file diff --git a/tasks/ostrovskaya-sf/lab_3/pic/pic1.jpg b/tasks/ostrovskaya-sf/lab_3/pic/pic1.jpg new file mode 100644 index 0000000..2f42897 Binary files /dev/null and b/tasks/ostrovskaya-sf/lab_3/pic/pic1.jpg differ diff --git a/tasks/ostrovskaya-sf/lab_3/pic/pic2.jpg b/tasks/ostrovskaya-sf/lab_3/pic/pic2.jpg new file mode 100644 index 0000000..302d42a Binary files /dev/null and b/tasks/ostrovskaya-sf/lab_3/pic/pic2.jpg differ diff --git a/tasks/ostrovskaya-sf/lab_3/pic/pic3.jpg b/tasks/ostrovskaya-sf/lab_3/pic/pic3.jpg new file mode 100644 index 0000000..97e080b Binary files /dev/null and b/tasks/ostrovskaya-sf/lab_3/pic/pic3.jpg differ diff --git a/tasks/ostrovskaya-sf/lab_3/pic/pic4.jpg b/tasks/ostrovskaya-sf/lab_3/pic/pic4.jpg new file mode 100644 index 0000000..9a51b8c Binary files /dev/null and b/tasks/ostrovskaya-sf/lab_3/pic/pic4.jpg differ diff --git a/tasks/ostrovskaya-sf/lab_3/pic/pic5.jpg b/tasks/ostrovskaya-sf/lab_3/pic/pic5.jpg new file mode 100644 index 0000000..44bb124 Binary files /dev/null and b/tasks/ostrovskaya-sf/lab_3/pic/pic5.jpg differ diff --git a/tasks/ostrovskaya-sf/lab_3/pic/pic6.jpg b/tasks/ostrovskaya-sf/lab_3/pic/pic6.jpg new file mode 100644 index 0000000..f3339b4 Binary files /dev/null and b/tasks/ostrovskaya-sf/lab_3/pic/pic6.jpg differ