distributed-computing/tasks/mikhailov-ys/Lab_4/Main/Consumer1/Program.cs

32 lines
972 B
C#
Raw Normal View History

2024-01-06 23:43:02 +04:00
using System.Text;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
var factory = new ConnectionFactory { HostName = "localhost" };
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();
channel.QueueDeclare(queue: "accepted");
channel.QueueBind(queue: "accepted",
exchange: "report",
routingKey: string.Empty);
Console.WriteLine(" [*] Waiting for messages.");
var consumer = new EventingBasicConsumer(channel);
consumer.Received += async (model, ea) =>
{
byte[] body = ea.Body.ToArray();
var message = Encoding.UTF8.GetString(body);
string outputText = $"Заявление принято к обработке {message}";
Console.WriteLine($" [x] Done. {outputText}");
channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
};
channel.BasicConsume(queue: "accepted",
autoAck: false,
consumer: consumer);
Console.WriteLine(" Press [enter] to exit.");
Console.ReadLine();