distributed-computing/tasks/nikiforova-ts/Lab_4/DApp/Consumer#1/Program.cs
2023-12-18 17:52:08 +04:00

30 lines
1.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Text;
using RabbitMQ.Client;
var фабрика = new ConnectionFactory { HostName = "localhost" };
using var подключение = фабрика.CreateConnection();
using var канал = подключение.CreateModel();
канал.ExchangeDeclare(exchange: "job", type: ExchangeType.Fanout);
Random rand = new Random();
foreach (var элемент in Enumerable.Range(0, 1000))
{
var сообщение = rand.Next().ToString();
var тело = Encoding.UTF8.GetBytes(сообщение);
канал.BasicPublish(exchange: "job",
routingKey: string.Empty,
basicProperties: null,
body: тело);
Console.WriteLine($" [x] Поступила заявка {сообщение}");
await Task.Delay(500);
}
Console.WriteLine(" Нажмите [Enter] для выхода.");
Console.ReadLine();
static string ПолучитьСообщение(string[] аргументы)
{
return ((аргументы.Length > 0) ? string.Join(" ", аргументы) : "info: Принято!");
}