distributed-computing/tasks/mikhailov-ys/lab_4/Main/Publisher/Program.cs

31 lines
897 B
C#
Raw Permalink Normal View History

2024-01-06 23:45:37 +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(exchange: "report", type: ExchangeType.Fanout);
Random rand = new Random();
foreach (var item in Enumerable.Range(0, 1000))
{
var message = rand.Next().ToString();
var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish(exchange: "report",
routingKey: string.Empty,
basicProperties: null,
body: body);
Console.WriteLine($" [x] Поступило заявление {message}");
await Task.Delay(500);
}
Console.WriteLine(" Press [enter] to exit.");
Console.ReadLine();
static string GetMessage(string[] args)
{
return ((args.Length > 0) ? string.Join(" ", args) : "info: Принято!");
}