Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Client.Wasm/Components/StudentCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
</CardHeader>
<CardBody>
<UnorderedList Unstyled>
<UnorderedListItem>Номер <Strong>№X "Название лабораторной"</Strong></UnorderedListItem>
<UnorderedListItem>Вариант <Strong>№Х "Название варианта"</Strong></UnorderedListItem>
<UnorderedListItem>Выполнена <Strong>Фамилией Именем 65ХХ</Strong> </UnorderedListItem>
<UnorderedListItem><Link To="https://puginarug.com/">Ссылка на форк</Link></UnorderedListItem>
<UnorderedListItem>Номер <Strong>№1 "Кеширование"</Strong></UnorderedListItem>
<UnorderedListItem>Вариант <Strong>№14 "Медицинский пациeнт"</Strong></UnorderedListItem>
<UnorderedListItem>Выполнена <Strong>Степановым Дмитрием 6511</Strong> </UnorderedListItem>
<UnorderedListItem><Link To="https://github.com/negniy/cloud-development.git">Ссылка на форк</Link></UnorderedListItem>
</UnorderedList>
</CardBody>
</Card>
12 changes: 6 additions & 6 deletions Client.Wasm/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchBrowser": false,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "http://localhost:5127",
"applicationUrl": "http://localhost:5128",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchBrowser": false,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:7282;http://localhost:5127",
"applicationUrl": "https://localhost:7283;http://localhost:5128",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchBrowser": false,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
}
4 changes: 2 additions & 2 deletions Client.Wasm/wwwroot/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
}
},
"AllowedHosts": "*",
"BaseAddress": ""
}
"BaseAddress": "http://localhost:5000/patient"
}
38 changes: 37 additions & 1 deletion CloudDevelopment.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36811.4
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client.Wasm", "Client.Wasm\Client.Wasm.csproj", "{AE7EEA74-2FE0-136F-D797-854FD87E022A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client.Wasm", "Client.Wasm\Client.Wasm.csproj", "{AE7EEA74-2FE0-136F-D797-854FD87E022A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatientApp.Generator", "GeneratorService\PatientApp.Generator.csproj", "{DB627DDE-E411-4B5B-9FE3-15F9A8EC1491}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatientApp.AppHost", "Patient\Patient.AppHost\PatientApp.AppHost.csproj", "{03605D0F-0E69-461D-9417-32DD06B53E23}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatientApp.ServiceDefaults", "Patient\Patient.ServiceDefaults\PatientApp.ServiceDefaults.csproj", "{DA24CCA7-7B4A-871C-985C-DBE0FA1F7524}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatientApp.Gateway", "Gateway\PatientApp.Gateway.csproj", "{AB6410EA-A027-B523-756F-6E77D0CA6F6B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatientApp.EventSink", "EventSink\PatientApp.EventSink.csproj", "{1DE31765-8D5C-4397-AF8C-829B6DB5B6F2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationTests", "IntegrationTests\IntegrationTests.csproj", "{01005A69-2B7C-4F8D-9C05-A060D4AB80EB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,6 +27,30 @@ Global
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Release|Any CPU.Build.0 = Release|Any CPU
{DB627DDE-E411-4B5B-9FE3-15F9A8EC1491}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DB627DDE-E411-4B5B-9FE3-15F9A8EC1491}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DB627DDE-E411-4B5B-9FE3-15F9A8EC1491}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DB627DDE-E411-4B5B-9FE3-15F9A8EC1491}.Release|Any CPU.Build.0 = Release|Any CPU
{03605D0F-0E69-461D-9417-32DD06B53E23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{03605D0F-0E69-461D-9417-32DD06B53E23}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03605D0F-0E69-461D-9417-32DD06B53E23}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03605D0F-0E69-461D-9417-32DD06B53E23}.Release|Any CPU.Build.0 = Release|Any CPU
{DA24CCA7-7B4A-871C-985C-DBE0FA1F7524}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DA24CCA7-7B4A-871C-985C-DBE0FA1F7524}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA24CCA7-7B4A-871C-985C-DBE0FA1F7524}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA24CCA7-7B4A-871C-985C-DBE0FA1F7524}.Release|Any CPU.Build.0 = Release|Any CPU
{AB6410EA-A027-B523-756F-6E77D0CA6F6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AB6410EA-A027-B523-756F-6E77D0CA6F6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB6410EA-A027-B523-756F-6E77D0CA6F6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB6410EA-A027-B523-756F-6E77D0CA6F6B}.Release|Any CPU.Build.0 = Release|Any CPU
{1DE31765-8D5C-4397-AF8C-829B6DB5B6F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1DE31765-8D5C-4397-AF8C-829B6DB5B6F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1DE31765-8D5C-4397-AF8C-829B6DB5B6F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1DE31765-8D5C-4397-AF8C-829B6DB5B6F2}.Release|Any CPU.Build.0 = Release|Any CPU
{01005A69-2B7C-4F8D-9C05-A060D4AB80EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{01005A69-2B7C-4F8D-9C05-A060D4AB80EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{01005A69-2B7C-4F8D-9C05-A060D4AB80EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01005A69-2B7C-4F8D-9C05-A060D4AB80EB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
33 changes: 33 additions & 0 deletions EventSink/Consumers/PatientCreatedConsumer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Text.Json;
using MassTransit;
using PatientApp.Generator.Models;
using PatientApp.EventSink.Storage;

namespace PatientApp.EventSink.Consumers;

public class PatientCreatedConsumer(
IStorageService storageService,
ILogger<PatientCreatedConsumer> logger)
: IConsumer<Patient>
{
public async Task Consume(
ConsumeContext<Patient> context)
{
var patient = context.Message;

logger.LogInformation(
"Received patient {Id}",
patient.Id);

var json =
JsonSerializer.Serialize(patient);

await storageService.SaveAsync(
$"{patient.Id}.json",
json);

logger.LogInformation(
"Patient {Id} saved to S3",
patient.Id);
}
}
23 changes: 23 additions & 0 deletions EventSink/PatientApp.EventSink.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="4.0.3.37" />
<PackageReference Include="AWSSDK.S3" Version="4.0.23" />
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="4.0.2.30" />
<PackageReference Include="LocalStack.Client.Extensions" Version="2.0.0" />
<PackageReference Include="MassTransit" Version="9.2.0-develop.138" />
<PackageReference Include="MassTransit.AmazonSQS" Version="9.2.0-develop.138" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.7" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GeneratorService\PatientApp.Generator.csproj" />
</ItemGroup>

</Project>
119 changes: 119 additions & 0 deletions EventSink/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using Amazon;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleanup

using Amazon.Runtime;
using Amazon.S3;
using Amazon.S3.Model;
using Amazon.SimpleNotificationService;
using Amazon.SQS;
using MassTransit;
using PatientApp.EventSink.Consumers;
using PatientApp.EventSink.Storage;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();

Comment on lines +11 to +14
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь не хватает builder.AddServiceDefaults();

builder.Services.AddSingleton<IAmazonS3>(_ =>
{
var config = new AmazonS3Config
{
ServiceURL = "http://localhost:4566",
ForcePathStyle = true,
UseHttp = true,
AuthenticationRegion = "us-east-1"
};

return new AmazonS3Client(
new BasicAWSCredentials("test", "test"),
config);
});

builder.Services.AddScoped<IStorageService, StorageService>();

builder.Services.AddMassTransit(x =>
{
x.AddConsumer<PatientCreatedConsumer>();

x.UsingAmazonSqs((context, cfg) =>
{
cfg.Host(
"us-east-1",
h =>
{
h.AccessKey("test");

h.SecretKey("test");

h.Config(new AmazonSQSConfig
{
ServiceURL = "http://localhost:4566",
AuthenticationRegion = "us-east-1",
UseHttp = true
});

h.Config(
new AmazonSimpleNotificationServiceConfig
{
ServiceURL =
"http://localhost:4566",

AuthenticationRegion =
"us-east-1",

UseHttp = true
});
});

cfg.ReceiveEndpoint(
"patients-queue",
e =>
{
e.ConfigureConsumeTopology = true;

e.ConfigureConsumer<
PatientCreatedConsumer>(
context);
});
});
});
Comment on lines +32 to +77
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если не ошибаюсь, на лекциях должно было говорится, что пользоваться MassTransit не стоит, все настроить можно без него, вот пример с лекций


var app = builder.Build();

app.MapControllers();

app.MapGet("/test-s3", async (
IAmazonS3 s3) =>
{
var buckets =
await s3.ListBucketsAsync();

return Results.Ok(
buckets.Buckets
.Select(x => x.BucketName)
.ToList());
});

app.MapGet("/test-files", async (
IAmazonS3 s3) =>
{
try
{
var response =
await s3.ListObjectsV2Async(
new ListObjectsV2Request
{
BucketName = "patients"
});

return Results.Ok(
response.S3Objects
.Select(x => x.Key)
.ToList());
}
catch
{
return Results.Ok(
new List<string>());
}
});

app.Run();
13 changes: 13 additions & 0 deletions EventSink/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"EventSink": {
"commandName": "Project",
"dotnetRunMessages": true,
"applicationUrl": "http://0.0.0.0:20829",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
6 changes: 6 additions & 0 deletions EventSink/Storage/IStorageService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace PatientApp.EventSink.Storage;

public interface IStorageService
{
public Task SaveAsync(string fileName, string content);
}
40 changes: 40 additions & 0 deletions EventSink/Storage/StorageService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Amazon.S3;
using Amazon.S3.Model;
using Amazon.S3.Util;

namespace PatientApp.EventSink.Storage;

public class StorageService(
IAmazonS3 s3Client) : IStorageService
{
private const string BucketName = "patients";

public async Task SaveAsync(
string fileName,
string content)
{
var exists =
await AmazonS3Util
.DoesS3BucketExistV2Async(
s3Client,
BucketName);

if (!exists)
{
await s3Client.PutBucketAsync(
new PutBucketRequest
{
BucketName = BucketName
});
}

var request = new PutObjectRequest
{
BucketName = BucketName,
Key = fileName,
ContentBody = content
};

await s3Client.PutObjectAsync(request);
}
}
8 changes: 8 additions & 0 deletions EventSink/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
12 changes: 12 additions & 0 deletions EventSink/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"EventSink": {
"Endpoint": "http://host.docker.internal:20829/subscription"
}
}
Loading
Loading