lab 3 30.11 done
This commit is contained in:
parent
d64b702b13
commit
8c6748cc74
@ -0,0 +1,86 @@
|
||||
# Отчет по лабораторной работе №3
|
||||
|
||||
Выполнил студент гр. ИСЭбд-41 Мытарин Е.С.
|
||||
|
||||
## REST API, Gateway и синхронный обмен между микросервисами
|
||||
|
||||
## Создание микросервисов
|
||||
|
||||
1. С помощью команды `dotnet new web -n worker-2` в терминале создал первый микросервис
|
||||
2. Добавил решение командой `dotnet new sln`
|
||||
3. Связал решение и проект командой `dotnet sln worker-2.sln add worker-2.csproj`
|
||||
4. Повторил действие для второго микросервиса
|
||||
5. Добавил библиотеку Swagger и OpenAi в проекты и запустил с помощью команды `dotnet run`
|
||||
|
||||
Скриншоты протестированных микросервисов:
|
||||
![](pic/1.png)
|
||||
![](pic/2.png)
|
||||
|
||||
## Реализация синхронного обмена
|
||||
|
||||
Реализовал код, который вызывает сихронно данные из соседнего микросервиса.
|
||||
|
||||
```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/3.png)
|
||||
|
||||
index.html на gateway-1:
|
||||
|
||||
![](pic/4.png)
|
||||
|
||||
worker-1:
|
||||
|
||||
![](pic/5.png)
|
||||
|
||||
worker-2:
|
||||
|
||||
![](pic/6.png)
|
BIN
tasks/mytarin_es/lab_3/pic/1.png
Normal file
BIN
tasks/mytarin_es/lab_3/pic/1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 41 KiB |
BIN
tasks/mytarin_es/lab_3/pic/2.png
Normal file
BIN
tasks/mytarin_es/lab_3/pic/2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
BIN
tasks/mytarin_es/lab_3/pic/3.png
Normal file
BIN
tasks/mytarin_es/lab_3/pic/3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
BIN
tasks/mytarin_es/lab_3/pic/4.png
Normal file
BIN
tasks/mytarin_es/lab_3/pic/4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
BIN
tasks/mytarin_es/lab_3/pic/5.png
Normal file
BIN
tasks/mytarin_es/lab_3/pic/5.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
BIN
tasks/mytarin_es/lab_3/pic/6.png
Normal file
BIN
tasks/mytarin_es/lab_3/pic/6.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
@ -6,7 +6,7 @@
|
||||
<title>Тестовое приложение для л/р 3</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Именно этот файл вы видите, когда открываете приложение.</p>
|
||||
<p>Мытарин Е.С. ИСЭбд-41.</p>
|
||||
<p><a href="/worker-1/">Отправить запрос к worker-1</a></p>
|
||||
<p><a href="/worker-2/">Отправить запрос к worker-2</a></p>
|
||||
</body>
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("worker-1")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+50cf3cd91240dc331235165635200161393875ec")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d64b702b1390dff3255929bb2b00605248500f1d")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("worker-1")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("worker-1")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
@ -1 +1 @@
|
||||
b8ae3c34e28363ae8927d69e636d3c331fd968023ab00e328e2a8f60b2777d3f
|
||||
b4384d6c7f5f0291b819e57beb7554a83883f51de1a9b79417abb0b571813599
|
||||
|
@ -1,10 +1,9 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Этот код создан программой.
|
||||
// Исполняемая версия:4.0.30319.42000
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||
// повторной генерации кода.
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,10 +1,9 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Этот код создан программой.
|
||||
// Исполняемая версия:4.0.30319.42000
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||
// повторной генерации кода.
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@ -14,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("worker-2")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+50cf3cd91240dc331235165635200161393875ec")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d64b702b1390dff3255929bb2b00605248500f1d")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("worker-2")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("worker-2")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
@ -1 +1 @@
|
||||
a2f886302caeb6f21989187f7b541e132abf94f8a32642d06c80e0bfd41abc9a
|
||||
4722328fc895d989f3d9529a0e32db57d2bf738a6e90864b9245732a0a8e723f
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user