DAS_2023_1/almukhammetov_bulat_lab_4/RabbitMQ/RabbitMQ/Program.cs
2024-01-06 18:37:17 +04:00

28 lines
796 B
C#

using RabbitMQ.Client;
using System.Text;
var factory = new ConnectionFactory() { HostName = "localhost" };
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
channel.ExchangeDeclare(exchange: "logs", type: ExchangeType.Fanout);
while (true)
{
string message = GetMessage();
var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish(exchange: "logs",
routingKey: "",
basicProperties: null,
body: body);
Console.WriteLine(" [x] Отпралено {0}", message);
Thread.Sleep(1000); // Ожидание 1 секунду
}
}
static string GetMessage()
{
return $"Log: {DateTime.Now}";
}