Commit 385dcf56 authored by Savorboard's avatar Savorboard

Add rabbitmq connection model create failed logs

parent 0e0fada1
...@@ -18,6 +18,7 @@ namespace DotNetCore.CAP.RabbitMQ ...@@ -18,6 +18,7 @@ namespace DotNetCore.CAP.RabbitMQ
private readonly ILogger<ConnectionChannelPool> _logger; private readonly ILogger<ConnectionChannelPool> _logger;
private readonly ConcurrentQueue<IModel> _pool; private readonly ConcurrentQueue<IModel> _pool;
private IConnection _connection; private IConnection _connection;
private static readonly object s_lock = new object();
private int _count; private int _count;
private int _maxSize; private int _maxSize;
...@@ -47,8 +48,15 @@ namespace DotNetCore.CAP.RabbitMQ ...@@ -47,8 +48,15 @@ namespace DotNetCore.CAP.RabbitMQ
IModel IConnectionChannelPool.Rent() IModel IConnectionChannelPool.Rent()
{ {
lock (s_lock)
{
while (_count > _maxSize)
{
Thread.SpinWait(1);
}
return Rent(); return Rent();
} }
}
bool IConnectionChannelPool.Return(IModel connection) bool IConnectionChannelPool.Return(IModel connection)
{ {
...@@ -120,7 +128,16 @@ namespace DotNetCore.CAP.RabbitMQ ...@@ -120,7 +128,16 @@ namespace DotNetCore.CAP.RabbitMQ
return model; return model;
} }
try
{
model = GetConnection().CreateModel(); model = GetConnection().CreateModel();
}
catch (Exception e)
{
_logger.LogError(e,"RabbitMQ channel model create failed!");
Console.WriteLine(e);
throw;
}
return model; return model;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment