forked from Alexey/DAS_2024_1
first work
This commit is contained in:
parent
c509e74465
commit
9d0fa199f7
6
.gitignore
vendored
6
.gitignore
vendored
@ -7,3 +7,9 @@
|
|||||||
/dozorova_alena_lab_2/ConsoleApp2/.vs
|
/dozorova_alena_lab_2/ConsoleApp2/.vs
|
||||||
/dozorova_alena_lab_2/ConsoleApp2/bin
|
/dozorova_alena_lab_2/ConsoleApp2/bin
|
||||||
/dozorova_alena_lab_2/ConsoleApp2/obj
|
/dozorova_alena_lab_2/ConsoleApp2/obj
|
||||||
|
/dozorova_alena_lab_3/PostService/.vs
|
||||||
|
/dozorova_alena_lab_3/WorkerService/.vs
|
||||||
|
/dozorova_alena_lab_4/Receive/bin
|
||||||
|
/dozorova_alena_lab_4/Receive/obj
|
||||||
|
/dozorova_alena_lab_4/Send/bin
|
||||||
|
/dozorova_alena_lab_4/Send/obj
|
||||||
|
29
dozorova_alena_lab_4/Receive/Program.cs
Normal file
29
dozorova_alena_lab_4/Receive/Program.cs
Normal 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();
|
14
dozorova_alena_lab_4/Receive/Receive.csproj
Normal file
14
dozorova_alena_lab_4/Receive/Receive.csproj
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="RabbitMQ.Client" Version="6.8.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
24
dozorova_alena_lab_4/Send/Program.cs
Normal file
24
dozorova_alena_lab_4/Send/Program.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
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);
|
||||||
|
|
||||||
|
const string message = "Hello World!";
|
||||||
|
var body = Encoding.UTF8.GetBytes(message);
|
||||||
|
|
||||||
|
channel.BasicPublish(exchange: string.Empty,
|
||||||
|
routingKey: "hello",
|
||||||
|
basicProperties: null,
|
||||||
|
body: body);
|
||||||
|
Console.WriteLine($" [x] Sent {message}");
|
||||||
|
|
||||||
|
Console.WriteLine(" Press [enter] to exit.");
|
||||||
|
Console.ReadLine();
|
14
dozorova_alena_lab_4/Send/Send.csproj
Normal file
14
dozorova_alena_lab_4/Send/Send.csproj
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="RabbitMQ.Client" Version="6.8.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
Reference in New Issue
Block a user