DAS_2024_1/kuzarin_maxim_lab_4/PublishSubscribe/Program.cs

24 lines
721 B
C#
Raw Normal View History

using PublishSubscribe;
string brokerHost = "localhost";
string exchangeName = "logs";
var sender = new ExchangeSender(brokerHost, "user", "password");
sender.AddExcange(exchangeName);
var receiver1 = new ExchangeReceiver(brokerHost, "user", "password");
var receiver2 = new ExchangeReceiver(brokerHost, "user", "password");
receiver1.SubscribeTo(exchangeName, message => Console.WriteLine($" [->1] Received: {message}"));
receiver2.SubscribeTo(exchangeName, message => Console.WriteLine($" [->2] Received: {message}"));
for (int i = 0; i < 10; i++)
{
var message = $"Messga number {i}";
Console.WriteLine($" [0->] Send: {message}");
sender.PublishToExchange(exchangeName, message);
}
while (true);