DAS_2024_1/kuzarin_maxim_lab_4/Consumer1/Program.cs

36 lines
1.3 KiB
C#
Raw Normal View History


using PublishSubscribe;
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") ?? "SorterIn";
var rabbitQueue = Environment.GetEnvironmentVariable("RABBIT_QUEUE") ?? "SorterFirst";
var HasDelay = bool.Parse(Environment.GetEnvironmentVariable("HAS_DELAY") ?? "false");
Thread.Sleep(2000);
var Receiver = new ExchangeReceiver(rabbitHost, rabbitUsername, rabbitPassword);
Receiver.SubscribeTo(rabbitExchange, (message) =>
{
var rnd = new Random();
var messageData = message.Split("|");
Console.WriteLine($"[<-]\tПришло сообщение\tId:{messageData[0]}\tType:{messageData[2]}\t Data:{string.Join(";", messageData.Skip(3))}");
if (HasDelay)
{
Thread.Sleep(rnd.Next(2000, 3000));
Console.WriteLine($"[\\/]\tОбработка сообщения {messageData[0]} завершена");
}
else
{
Console.WriteLine($"[\\/]\tСообщение {messageData[0]} обрабатывается мгновенно");
}
},
rabbitQueue);
while (true) ;