25 lines
830 B
C#
25 lines
830 B
C#
using RabbitMQ.Client;
|
|
using RabbitMQ.Client.Events;
|
|
using System.Text;
|
|
|
|
var factory = new ConnectionFactory() { HostName = "localhost:7003" };
|
|
using (var connection = factory.CreateConnection())
|
|
using (var channel = connection.CreateModel())
|
|
{
|
|
channel.QueueDeclare(queue: "",
|
|
durable: false,
|
|
exclusive: false,
|
|
autoDelete: false,
|
|
arguments: null);
|
|
|
|
var consumer = new EventingBasicConsumer(channel);
|
|
consumer.Received += (model, ea) =>
|
|
{
|
|
var body = ea.Body.ToArray();
|
|
var message = Encoding.UTF8.GetString(body);
|
|
Console.WriteLine("Received {0}", message);
|
|
};
|
|
channel.BasicConsume(queue: "",
|
|
autoAck: true,
|
|
consumer: consumer);
|
|
} |