diff --git a/.gitignore b/.gitignore index 697082a..ea4af46 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,9 @@ /dozorova_alena_lab_2/ConsoleApp2/.vs /dozorova_alena_lab_2/ConsoleApp2/bin /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 diff --git a/dozorova_alena_lab_4/Receive/Program.cs b/dozorova_alena_lab_4/Receive/Program.cs new file mode 100644 index 0000000..ffe992b --- /dev/null +++ b/dozorova_alena_lab_4/Receive/Program.cs @@ -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(); \ No newline at end of file diff --git a/dozorova_alena_lab_4/Receive/Receive.csproj b/dozorova_alena_lab_4/Receive/Receive.csproj new file mode 100644 index 0000000..f72406b --- /dev/null +++ b/dozorova_alena_lab_4/Receive/Receive.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + diff --git a/dozorova_alena_lab_4/Send/Program.cs b/dozorova_alena_lab_4/Send/Program.cs new file mode 100644 index 0000000..4e0f5c2 --- /dev/null +++ b/dozorova_alena_lab_4/Send/Program.cs @@ -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(); \ No newline at end of file diff --git a/dozorova_alena_lab_4/Send/Send.csproj b/dozorova_alena_lab_4/Send/Send.csproj new file mode 100644 index 0000000..f72406b --- /dev/null +++ b/dozorova_alena_lab_4/Send/Send.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8.0 + enable + enable + + + + + + +