forked from Alexey/DAS_2024_1
52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
|
||
using PIHelperSh.RandomEx.Extentions;
|
||
using PublishSubscribe;
|
||
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") ?? "SorterIn";
|
||
|
||
var Sender = new ExchangeSender(rabbitHost, rabbitUsername, rabbitPassword);
|
||
|
||
Sender.AddExcange(rabbitExchange);
|
||
|
||
var rnd = new Random();
|
||
|
||
while (true)
|
||
{
|
||
StringBuilder sb = new();
|
||
|
||
sb.Append(rnd.Next().ToString("0000000000"));
|
||
sb.Append("|");
|
||
|
||
switch (rnd.Next(4))
|
||
{
|
||
case 0:
|
||
sb.Append($"0|Прибыла послыка|{rnd.NextString("[0-9]7")}");
|
||
break;
|
||
case 1:
|
||
sb.Append($"1|Прибыла послыка без штрих кода|");
|
||
break;
|
||
case 2:
|
||
var count = rnd.Next(2,8);
|
||
sb.Append($"2|Прибыла послыка c несколькими кодами|{count}");
|
||
for (int i = 0; i < count; i++)
|
||
{
|
||
sb.Append($"|{rnd.NextString("[0-9]7")}");
|
||
}
|
||
break;
|
||
default:
|
||
sb.Append($"3|Произошла ошибка|{rnd.Next(500,599)}");
|
||
break;
|
||
}
|
||
|
||
var text = sb.ToString();
|
||
Console.WriteLine($"[->]\tОтправлено сообщение\t{text}");
|
||
Sender.PublishToExchange(rabbitExchange, text);
|
||
|
||
await Task.Delay(1000);
|
||
}
|
||
|