mironov-eo-lab-4

This commit is contained in:
2023-12-06 00:06:50 +03:00
parent 39090162a2
commit 67d9a7be51
43 changed files with 1290 additions and 0 deletions

View File

@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34322.80
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "worker-1", "worker-1\worker-1.csproj", "{A6034879-0CBB-4385-9D2F-B399BC7A0D1E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A6034879-0CBB-4385-9D2F-B399BC7A0D1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A6034879-0CBB-4385-9D2F-B399BC7A0D1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A6034879-0CBB-4385-9D2F-B399BC7A0D1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A6034879-0CBB-4385-9D2F-B399BC7A0D1E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B2FED482-66BF-47C8-8220-8C75B48CD004}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,28 @@
using System.Text;
using RabbitMQ.Client;
var factory = new ConnectionFactory { HostName = "localhost" };
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();
channel.QueueDeclare(queue: "hello",
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
foreach (var item in Enumerable.Range(0, 100))
{
string message = "Hello World!";
var body = Encoding.UTF8.GetBytes(message + item);
channel.BasicPublish(exchange: string.Empty,
routingKey: "hello",
basicProperties: null,
body: body);
Console.WriteLine($" [x] Sent {message} iteration {item}");
await Task.Delay(1000);
}
Console.WriteLine(" Press [enter] to exit.");
Console.ReadLine();

View File

@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>worker_1</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RabbitMQ.Client" Version="6.7.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34322.80
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "worker-2", "worker-2\worker-2.csproj", "{33E9DE33-CF9C-4343-A2C4-005FCFCF5A9F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{33E9DE33-CF9C-4343-A2C4-005FCFCF5A9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{33E9DE33-CF9C-4343-A2C4-005FCFCF5A9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33E9DE33-CF9C-4343-A2C4-005FCFCF5A9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33E9DE33-CF9C-4343-A2C4-005FCFCF5A9F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EC5624E4-6B53-42F7-A049-AF1FB2306297}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,29 @@
using System.Text;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
var factory = new ConnectionFactory { HostName = "localhost" };
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();
channel.QueueDeclare(queue: "hello",
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
Console.WriteLine(" [*] Waiting for messages.");
var consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, ea) =>
{
var body = ea.Body.ToArray();
var message = Encoding.UTF8.GetString(body);
Console.WriteLine($" [x] Received {message}");
};
channel.BasicConsume(queue: "hello",
autoAck: true,
consumer: consumer);
Console.WriteLine(" Press [enter] to exit.");
Console.ReadLine();

View File

@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>worker_2</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RabbitMQ.Client" Version="6.7.0" />
</ItemGroup>
</Project>