ctrl
🧩 Syntax:
using MassTransit;
using RabbitSecurity;
namespace Kontroler
{
internal class Program
{
static async Task Main(string[] args)
{
var bus = Bus.Factory.CreateUsingRabbitMq(sbc => {
sbc.Host("rattlesnake.rmq.cloudamqp.com", "rfrwranm",
h => {
var credentials = new RabbitSecurityCredentials();
h.Username(credentials.GetUser());
h.Password(credentials.GetPassword());
});
});
Console.WriteLine("Jestem kontroler");
await bus.StartAsync();
while (true)
{
ConsoleKeyInfo keyInfo = Console.ReadKey();
if(keyInfo.Key == ConsoleKey.S)
{
var polecenie = new Wiadomości.Ustaw { Dziala = true };
var tsk = bus.GetSendEndpoint(new Uri("rabbitmq://localhost/polecenia"));
tsk.Wait();
var sendEp = tsk.Result;
await sendEp.Send<Wiadomości.IUstaw>(polecenie);
Console.WriteLine("\nWiadomosci beda publikowane");
}
else if (keyInfo.Key == ConsoleKey.T)
{
var polecenie = new Wiadomości.Ustaw { Dziala = false };
var tsk = bus.GetSendEndpoint(new Uri("rabbitmq://localhost/polecenia"));
tsk.Wait();
var sendEp = tsk.Result;
await sendEp.Send<Wiadomości.IUstaw>(polecenie);
Console.WriteLine("\nWiadomosci nie beda publikowane");
}
else if (keyInfo.Key == ConsoleKey.Escape)
{
break;
}
}
await bus.StopAsync();
}
}
}