DAS_2024_1/dozorova_alena_lab_4/Publisher/Program.cs

41 lines
1.2 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Publisher;
using System.Text;
var rabbitHost = Environment.GetEnvironmentVariable("RABBIT_HOST") ?? "localhost";
var rabbitUsername = Environment.GetEnvironmentVariable("RABBIT_USERNAME") ?? "user";
var rabbitPassword = Environment.GetEnvironmentVariable("RABBIT_PASSWORD") ?? "password";
var rabbitExchange = Environment.GetEnvironmentVariable("RABBIT_EXCHANGE") ?? "ReportIn";
var sender = new Sender(rabbitHost, rabbitUsername, rabbitPassword);
sender.AddExcange(rabbitExchange);
var rnd = new Random();
while (true)
{
StringBuilder sb = new();
var type = rnd.Next();
switch (type%2)
{
case 0:
{
sb.Append($"Был запрошен отчет о данных под номером {rnd.Next(1000)}");
break;
}
case 1:
{
sb.Append($"Был запрошен отчет об ошибках под номером {rnd.Next(1000)}");
break;
}
}
var text = sb.ToString();
Console.WriteLine($"Было опубликовано сообщение: {text}");
sender.PublishToExchange(rabbitExchange, text);
await Task.Delay(1000);
}