43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
using RabbitMQ.Client;
|
|
using RabbitMQ.Client.Events;
|
|
using System.Text;
|
|
|
|
namespace JSONParser.RabbitMQ
|
|
{
|
|
public class RabbitConnection
|
|
{
|
|
public async void ReciveMessage()
|
|
{
|
|
var factory = new ConnectionFactory
|
|
{
|
|
HostName = "astsrvrabbit1",
|
|
UserName = "erp",
|
|
Password = @"Z!1;Q5#GE4v",
|
|
VirtualHost = "erp"
|
|
};
|
|
|
|
var connection = await factory.CreateConnectionAsync();
|
|
var channel = await connection.CreateChannelAsync();
|
|
|
|
await channel.QueueDeclareAsync(
|
|
queue: "hrm",
|
|
durable: false,
|
|
exclusive: false,
|
|
autoDelete: false,
|
|
arguments: null);
|
|
var consumer = new AsyncEventingBasicConsumer(channel);
|
|
consumer.ReceivedAsync += async (model, ea) =>
|
|
{
|
|
var body = ea.Body.ToArray();
|
|
var message = Encoding.UTF8.GetString(body);
|
|
Console.WriteLine($" [x] Received {message}");
|
|
await Task.Yield();
|
|
};
|
|
await channel.BasicConsumeAsync(
|
|
queue: "hrm",
|
|
autoAck: true,
|
|
consumer: consumer);
|
|
}
|
|
}
|
|
}
|