feat: Add RabbitMQ
This commit is contained in:
parent
d3034c1a06
commit
8902080336
15 changed files with 2292 additions and 2069 deletions
49
BMA.EHR.Infrastructure/MessageQueue/RabbitMQConsumer.cs
Normal file
49
BMA.EHR.Infrastructure/MessageQueue/RabbitMQConsumer.cs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
using System.Text;
|
||||
using RabbitMQ.Client.Events;
|
||||
|
||||
namespace BMA.EHR.Infrastructure.MessageQueue
|
||||
{
|
||||
public class RabbitMQConsumer
|
||||
{
|
||||
private readonly RabbitMQConnection _connection;
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="connection"></param>
|
||||
public RabbitMQConsumer(RabbitMQConnection connection)
|
||||
{
|
||||
_connection = connection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void StartReceiving()
|
||||
{
|
||||
var channel = _connection.GetChannel();
|
||||
channel.QueueDeclare(queue: "myqueue",
|
||||
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(" [x] Received {0}", message);
|
||||
};
|
||||
|
||||
channel.BasicConsume(queue: "myqueue",
|
||||
autoAck: true,
|
||||
consumer: consumer,
|
||||
consumerTag: "",
|
||||
noLocal: false,
|
||||
exclusive: false,
|
||||
arguments: null);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue