distributed-computing/tasks/khalitova-am/lab_4/demoApp/Publisher/Program.cs
2023-12-18 09:52:45 +04:00

31 lines
885 B
C#

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: "job", 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: "job",
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: Принято!");
}