distributed-computing/tasks/mutriskov-ds/lab_4/tut2/NewTask/Program.cs

29 lines
817 B
C#
Raw Normal View History

2024-01-08 23:04:03 +04:00
using System.Text;
using RabbitMQ.Client;
var factory = new ConnectionFactory { HostName = "localhost" };
using (var connection = factory.CreateConnection())
{
using (var channel = connection.CreateModel())
{
channel.QueueDeclare("task_queue", true, false, false, null);
var message = GetMessage(args);
var body = Encoding.UTF8.GetBytes(message);
var properties = channel.CreateBasicProperties();
properties.Persistent = true;
channel.BasicPublish(string.Empty, "task_queue", properties, body);
Console.WriteLine($" [x] Sent {message}");
Console.WriteLine(" Press [enter] to exit.");
Console.ReadLine();
}
}
static string GetMessage(string[] args)
{
return (args.Length > 0 ? string.Join(" ", args) : "Hello World!");
}