36 lines
1.1 KiB
C#
36 lines
1.1 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.ExchangeDeclare(exchange: "reports", type: ExchangeType.Fanout);
|
|
|
|
channel.QueueDeclare("queue1");
|
|
channel.QueueBind(queue: "queue1",
|
|
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);
|
|
|
|
Thread.Sleep(2500);
|
|
|
|
var reportNumber = message.Split('#')[1];
|
|
Console.WriteLine($" [x] Отчет #{reportNumber} создан.");
|
|
|
|
channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
|
|
};
|
|
channel.BasicConsume(queue: "queue1",
|
|
autoAck: true,
|
|
consumer: consumer);
|
|
|
|
Console.WriteLine(" Нажмите [enter] чтобы выйти.");
|
|
Console.ReadLine(); |