Revert "Add Queue to Dependency Injection (Optimize)"
This reverts commit cf7a79166a.
This commit is contained in:
parent
cf7a79166a
commit
a27f3551d8
3 changed files with 35 additions and 118 deletions
|
|
@ -14,7 +14,6 @@ using BMA.EHR.Leave.Service.DTOs.ChangeRound;
|
|||
using BMA.EHR.Leave.Service.DTOs.CheckIn;
|
||||
using BMA.EHR.Leave.Service.DTOs.DutyTime;
|
||||
using BMA.EHR.Leave.Service.DTOs.LeaveRequest;
|
||||
using BMA.EHR.Leave.Service.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
|
@ -59,10 +58,6 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
|
||||
private readonly string _bucketName = "check-in";
|
||||
|
||||
private readonly string _fakeQueueName = "fake-checkin-queue";
|
||||
private readonly string _realQueueName = "checkin-queue";
|
||||
private readonly RabbitCheckInService _rabbitCheckInService;
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constuctor and Destructor "
|
||||
|
|
@ -80,8 +75,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
AdditionalCheckRequestRepository additionalCheckRequestRepository,
|
||||
UserCalendarRepository userCalendarRepository,
|
||||
CommandRepository commandRepository,
|
||||
LeaveRequestRepository leaveRequestRepository,
|
||||
RabbitCheckInService rabbitCheckInService)
|
||||
LeaveRequestRepository leaveRequestRepository)
|
||||
{
|
||||
_dutyTimeRepository = dutyTimeRepository;
|
||||
_context = context;
|
||||
|
|
@ -97,7 +91,6 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
_userCalendarRepository = userCalendarRepository;
|
||||
_commandRepository = commandRepository;
|
||||
_leaveRequestRepository = leaveRequestRepository;
|
||||
_rabbitCheckInService = rabbitCheckInService;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -465,32 +458,27 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
Token = AccessToken ?? ""
|
||||
};
|
||||
|
||||
//// create connection
|
||||
//var factory = new ConnectionFactory()
|
||||
//{
|
||||
// HostName = _configuration["Rabbit:Host"],
|
||||
// UserName = _configuration["Rabbit:User"],
|
||||
// Password = _configuration["Rabbit:Password"],
|
||||
//};
|
||||
// create connection
|
||||
var factory = new ConnectionFactory()
|
||||
{
|
||||
HostName = _configuration["Rabbit:Host"],
|
||||
UserName = _configuration["Rabbit:User"],
|
||||
Password = _configuration["Rabbit:Password"],
|
||||
};
|
||||
|
||||
//// create channel
|
||||
//using var connection = factory.CreateConnection();
|
||||
//using var channel = connection.CreateModel();
|
||||
//channel.QueueDeclare(queue: "checkin-queue", durable: false, exclusive: false, autoDelete: false, arguments: null);
|
||||
|
||||
//// แปลง Object เป็น JSON สตริง
|
||||
//var serializedObject = JsonConvert.SerializeObject(checkData);
|
||||
|
||||
//// แปลง JSON สตริงเป็น byte array
|
||||
//var body = Encoding.UTF8.GetBytes(serializedObject);
|
||||
|
||||
//channel.BasicPublish(exchange: "", routingKey: "checkin-queue", basicProperties: null, body: body);
|
||||
//Console.WriteLine($"Send to Queue: {serializedObject}");
|
||||
// create channel
|
||||
using var connection = factory.CreateConnection();
|
||||
using var channel = connection.CreateModel();
|
||||
channel.QueueDeclare(queue: "checkin-queue", durable: false, exclusive: false, autoDelete: false, arguments: null);
|
||||
|
||||
// แปลง Object เป็น JSON สตริง
|
||||
var serializedObject = JsonConvert.SerializeObject(checkData);
|
||||
var body = Encoding.UTF8.GetBytes(serializedObject);
|
||||
_rabbitCheckInService.SendMessageToQueue(_realQueueName, body);
|
||||
|
||||
// แปลง JSON สตริงเป็น byte array
|
||||
var body = Encoding.UTF8.GetBytes(serializedObject);
|
||||
|
||||
channel.BasicPublish(exchange: "", routingKey: "checkin-queue", basicProperties: null, body: body);
|
||||
Console.WriteLine($"Send to Queue: {serializedObject}");
|
||||
|
||||
return Success(new { date = currentDate });
|
||||
}
|
||||
|
|
@ -512,25 +500,27 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
{
|
||||
var currentDate = DateTime.Now;
|
||||
|
||||
//// create connection
|
||||
//var factory = new ConnectionFactory()
|
||||
//{
|
||||
// HostName = _configuration["Rabbit:Host"],
|
||||
// UserName = _configuration["Rabbit:User"],
|
||||
// Password = _configuration["Rabbit:Password"],
|
||||
//};
|
||||
// create connection
|
||||
var factory = new ConnectionFactory()
|
||||
{
|
||||
HostName = _configuration["Rabbit:Host"],
|
||||
UserName = _configuration["Rabbit:User"],
|
||||
Password = _configuration["Rabbit:Password"],
|
||||
};
|
||||
|
||||
//// create channel
|
||||
//using var connection = factory.CreateConnection();
|
||||
//using var channel = connection.CreateModel();
|
||||
//channel.QueueDeclare(queue: "fake-checkin-queue", durable: false, exclusive: false, autoDelete: false, arguments: null);
|
||||
// create channel
|
||||
using var connection = factory.CreateConnection();
|
||||
using var channel = connection.CreateModel();
|
||||
channel.QueueDeclare(queue: "fake-checkin-queue", durable: false, exclusive: false, autoDelete: false, arguments: null);
|
||||
|
||||
// แปลง Object เป็น JSON สตริง
|
||||
var serializedObject = JsonConvert.SerializeObject(data);
|
||||
var body = Encoding.UTF8.GetBytes(serializedObject);
|
||||
_rabbitCheckInService.SendMessageToQueue(_fakeQueueName, body);
|
||||
|
||||
//channel.BasicPublish(exchange: "", routingKey: "fake-checkin-queue", basicProperties: null, body: body);
|
||||
//Console.WriteLine($"Send to Queue: {serializedObject}");
|
||||
// แปลง JSON สตริงเป็น byte array
|
||||
var body = Encoding.UTF8.GetBytes(serializedObject);
|
||||
|
||||
channel.BasicPublish(exchange: "", routingKey: "fake-checkin-queue", basicProperties: null, body: body);
|
||||
Console.WriteLine($"Send to Queue: {serializedObject}");
|
||||
|
||||
return Success(new { date = currentDate });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,6 @@ using System.Transactions;
|
|||
using BMA.EHR.Leave.Service.Filters;
|
||||
using Hangfire.Common;
|
||||
using BMA.EHR.Application.Repositories.Leaves.TimeAttendants;
|
||||
using RabbitMQ.Client;
|
||||
using BMA.EHR.Leave.Service.Services;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
{
|
||||
|
|
@ -30,51 +28,6 @@ var builder = WebApplication.CreateBuilder(args);
|
|||
var key = builder.Configuration["Jwt:Key"];
|
||||
|
||||
|
||||
// ตั้งค่า RabbitMQ connection
|
||||
builder.Services.AddSingleton<IConnection>(sp =>
|
||||
{
|
||||
var factory = new ConnectionFactory()
|
||||
{
|
||||
HostName = builder.Configuration["Rabbit:Host"],
|
||||
UserName = builder.Configuration["Rabbit:User"],
|
||||
Password = builder.Configuration["Rabbit:Password"],
|
||||
};
|
||||
return factory.CreateConnection();
|
||||
});
|
||||
|
||||
|
||||
builder.Services.AddSingleton<IModel>(sp =>
|
||||
{
|
||||
var connection = sp.GetRequiredService<IConnection>();
|
||||
var channel = connection.CreateModel();
|
||||
|
||||
// ประกาศ queue
|
||||
channel.QueueDeclare(queue: "fake-checkin-queue",
|
||||
durable: true,
|
||||
exclusive: false,
|
||||
autoDelete: false,
|
||||
arguments: null);
|
||||
|
||||
return channel;
|
||||
});
|
||||
|
||||
|
||||
builder.Services.AddSingleton<IModel>(sp =>
|
||||
{
|
||||
var connection = sp.GetRequiredService<IConnection>();
|
||||
var channel = connection.CreateModel();
|
||||
|
||||
// ประกาศ queue
|
||||
channel.QueueDeclare(queue: "checkin-queue",
|
||||
durable: true,
|
||||
exclusive: false,
|
||||
autoDelete: false,
|
||||
arguments: null);
|
||||
|
||||
return channel;
|
||||
});
|
||||
|
||||
|
||||
IdentityModelEventSource.ShowPII = true;
|
||||
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
|
|
@ -136,8 +89,6 @@ var builder = WebApplication.CreateBuilder(args);
|
|||
builder.Services.AddPersistence(builder.Configuration);
|
||||
builder.Services.AddLeavePersistence(builder.Configuration);
|
||||
|
||||
builder.Services.AddSingleton<RabbitCheckInService>();
|
||||
|
||||
builder.Services.AddControllers(options =>
|
||||
{
|
||||
options.SuppressAsyncSuffixInActionNames = false;
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
using RabbitMQ.Client;
|
||||
using System.Text;
|
||||
|
||||
namespace BMA.EHR.Leave.Service.Services
|
||||
{
|
||||
public class RabbitCheckInService
|
||||
{
|
||||
private readonly IModel _channel;
|
||||
|
||||
public RabbitCheckInService(IModel channel)
|
||||
{
|
||||
_channel = channel;
|
||||
}
|
||||
|
||||
public void SendMessageToQueue(string queueName, byte[] body)
|
||||
{
|
||||
//var body = Encoding.UTF8.GetBytes(message);
|
||||
_channel.BasicPublish(exchange: "",
|
||||
routingKey: queueName,
|
||||
basicProperties: null,
|
||||
body: body);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue