distributed-computing/tasks/kazakov-ev/lab_4/MainTask/Publisher/Publisher.cs

31 lines
905 B
C#
Raw Normal View History

2023-12-18 13:22:22 +04:00
using System.Text;
using RabbitMQ.Client;
Random rand = new Random();
var factory = new ConnectionFactory { HostName = "localhost" };
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();
channel.ExchangeDeclare(exchange: "post", type: ExchangeType.Fanout);
foreach (var item in Enumerable.Range(0, 1000))
{
var message = rand.Next().ToString();
var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish(exchange: "post",
routingKey: string.Empty,
basicProperties: null,
body: body);
Console.WriteLine($" [x] Письмо готово {message}");
await Task.Delay(500);
}
Console.WriteLine(" Нажми [enter] чтобы выйти.");
Console.ReadLine();
static string GetMessage(string[] args)
{
return ((args.Length > 0) ? string.Join(" ", args) : "info: Привет Мир!");
}