using System.Text;
using Newtonsoft.Json;
namespace BMA.EHR.Infrastructure.MessageQueue
{
public class RabbitMQProducer
{
private readonly RabbitMQConnection _connection;
private const string INSIGNIA_QUEUE = "bma_insignia_request";
///
///
///
///
public RabbitMQProducer(RabbitMQConnection connection)
{
_connection = connection;
}
///
///
///
///
public void SendMessage(string message)
{
var channel = _connection.GetChannel();
channel.QueueDeclare(queue: "myqueue",
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish(exchange: "",
routingKey: "myqueue",
mandatory: false,
basicProperties: null,
body: body);
}
public void CalculateInsignia(Guid periodId)
{
var channel = _connection.GetChannel();
channel.QueueDeclare(queue: INSIGNIA_QUEUE,
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
// var req = new InsigniaRequestPeriod
// {
// PeriodId = periodId
// };
// var serializedObject = JsonConvert.SerializeObject(req);
var body = Encoding.UTF8.GetBytes(periodId.ToString("D"));
channel.BasicPublish(exchange: "",
routingKey: INSIGNIA_QUEUE,
mandatory: false,
basicProperties: null,
body: body);
}
}
}