feat: Change RAbbitMQ Conenction to Pool and Add k6 Test Script for max request per second.
This commit is contained in:
parent
0bac3630ec
commit
f5355728ab
7 changed files with 186 additions and 44 deletions
53
BMA.EHR.Leave/Services/RabbitMqConnectionPoolPolicy.cs
Normal file
53
BMA.EHR.Leave/Services/RabbitMqConnectionPoolPolicy.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using Microsoft.Extensions.ObjectPool;
|
||||
using RabbitMQ.Client;
|
||||
|
||||
namespace BMA.EHR.Leave.Service.Services;
|
||||
|
||||
public class RabbitMqConnectionPoolPolicy : IPooledObjectPolicy<IModel>
|
||||
{
|
||||
#region " Fields "
|
||||
|
||||
private readonly IConnection _connection;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constructor and Destructor "
|
||||
|
||||
public RabbitMqConnectionPoolPolicy(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
|
||||
var factory = new ConnectionFactory()
|
||||
{
|
||||
HostName = _configuration["Rabbit:Host"],
|
||||
UserName = _configuration["Rabbit:User"],
|
||||
Password = _configuration["Rabbit:Password"]
|
||||
};
|
||||
_connection = factory.CreateConnection();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Methods "
|
||||
|
||||
public IModel Create()
|
||||
{
|
||||
return _connection.CreateModel();
|
||||
}
|
||||
|
||||
public bool Return(IModel obj)
|
||||
{
|
||||
if (obj.IsOpen)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
obj.Dispose();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue