distributed-computing/tasks/mutriskov-ds/lab_4/MainTask/Publisher/Program.cs

21 lines
596 B
C#
Raw Normal View History

2024-01-08 23:04:03 +04:00
using System.Text;
using RabbitMQ.Client;
var factory = new ConnectionFactory { HostName = "localhost" };
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();
channel.ExchangeDeclare("reports", ExchangeType.Fanout);
var rand = new Random();
while (true)
{
var message = $"Необходимо создать отчет #{rand.Next()}";
var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish("reports", string.Empty, null, body);
Console.WriteLine($" [x] Отправлено \"{message}\"");
Thread.Sleep(1000);
}