32 lines
1.0 KiB
C#
32 lines
1.0 KiB
C#
|
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("queue2");
|
|||
|
channel.QueueBind(queue: "queue2",
|
|||
|
exchange: "reports",
|
|||
|
routingKey: string.Empty);
|
|||
|
|
|||
|
Console.WriteLine(" [*] Ожидание сообщения");
|
|||
|
|
|||
|
var consumer = new EventingBasicConsumer(channel);
|
|||
|
consumer.Received += (model, ea) =>
|
|||
|
{
|
|||
|
byte[] body = ea.Body.ToArray();
|
|||
|
var message = Encoding.UTF8.GetString(body);
|
|||
|
|
|||
|
var reportNumber = message.Split('#')[1];
|
|||
|
Console.WriteLine($" [x] Отчет #{reportNumber} создан.");
|
|||
|
|
|||
|
channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
|
|||
|
};
|
|||
|
channel.BasicConsume(queue: "queue2",
|
|||
|
autoAck: true,
|
|||
|
consumer: consumer);
|
|||
|
|
|||
|
Console.WriteLine(" Нажмите [enter] чтобы выйти.");
|
|||
|
Console.ReadLine();
|