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

26 lines
808 B
C#
Raw Permalink 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();
2024-01-09 00:42:05 +04:00
channel.ExchangeDeclare(exchange: "reports", type: ExchangeType.Fanout);
Random rand = new Random();
foreach (var item in Enumerable.Range(0, 1000))
2024-01-08 23:04:03 +04:00
{
var message = $"Необходимо создать отчет #{rand.Next()}";
2024-01-09 00:42:05 +04:00
2024-01-08 23:04:03 +04:00
var body = Encoding.UTF8.GetBytes(message);
2024-01-09 00:42:05 +04:00
channel.BasicPublish(exchange: "reports",
routingKey: string.Empty,
basicProperties: null,
body: body);
2024-01-08 23:04:03 +04:00
2024-01-09 00:42:05 +04:00
Console.WriteLine($" [x] Поступила работа {message}");
await Task.Delay(1000);
}
2024-01-08 23:04:03 +04:00
2024-01-09 00:42:05 +04:00
Console.WriteLine(" Press [enter] to exit.");
Console.ReadLine();