Merge branch 'develop' into bugfix/fixed-closing-delete-user-dialog
This commit is contained in:
commit
9a48bc19b3
@ -81,24 +81,40 @@ public static class ServiceCollectionExtension
|
||||
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
|
||||
{
|
||||
var cfg = sp.GetRequiredService<IConfiguration>();
|
||||
var settings = cfg.GetSection("RabbitMQ").Get<RabbitMQSettings>();
|
||||
|
||||
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
|
||||
|
||||
var factory = new ConnectionFactory()
|
||||
{
|
||||
HostName = settings.HostName,
|
||||
DispatchConsumersAsync = true
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(settings.UserName))
|
||||
if (!string.IsNullOrEmpty(rabbitMQConfiguration.EndpointUri))
|
||||
{
|
||||
factory.UserName = settings.UserName;
|
||||
factory.Endpoint = new AmqpTcpEndpoint(new Uri(rabbitMQConfiguration.EndpointUri));
|
||||
}
|
||||
else
|
||||
{
|
||||
factory.HostName = rabbitMQConfiguration.HostName;
|
||||
factory.UserName = rabbitMQConfiguration.UserName;
|
||||
factory.Password = rabbitMQConfiguration.Password;
|
||||
factory.Port = rabbitMQConfiguration.Port;
|
||||
factory.VirtualHost = rabbitMQConfiguration.VirtualHost;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(settings.Password))
|
||||
if (rabbitMQConfiguration.EnableSsl)
|
||||
{
|
||||
factory.Password = settings.Password;
|
||||
factory.Ssl = new SslOption
|
||||
{
|
||||
Enabled = rabbitMQConfiguration.EnableSsl,
|
||||
Version = SslProtocols.Tls12
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(rabbitMQConfiguration.SslCertPath))
|
||||
{
|
||||
factory.Ssl.CertPath = rabbitMQConfiguration.SslCertPath;
|
||||
factory.Ssl.ServerName = rabbitMQConfiguration.SslServerName;
|
||||
}
|
||||
}
|
||||
|
||||
var retryCount = 5;
|
||||
|
@ -24,13 +24,15 @@
|
||||
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
|
||||
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
|
||||
using System.Security.Authentication;
|
||||
|
||||
namespace ASC.Common.Caching;
|
||||
|
||||
[Singletone]
|
||||
public class RabbitMQCache<T> : IDisposable, ICacheNotify<T> where T : IMessage<T>, new()
|
||||
{
|
||||
private IConnection _connection;
|
||||
private readonly IConnectionFactory _connectionFactory;
|
||||
private readonly ConnectionFactory _factory;
|
||||
|
||||
private IModel _consumerChannel;
|
||||
private readonly Guid _instanceId;
|
||||
@ -53,14 +55,37 @@ public class RabbitMQCache<T> : IDisposable, ICacheNotify<T> where T : IMessage<
|
||||
|
||||
var rabbitMQConfiguration = configuration.GetSection("rabbitmq").Get<RabbitMQSettings>();
|
||||
|
||||
_connectionFactory = new ConnectionFactory
|
||||
{
|
||||
HostName = rabbitMQConfiguration.HostName,
|
||||
UserName = rabbitMQConfiguration.UserName,
|
||||
Password = rabbitMQConfiguration.Password
|
||||
};
|
||||
_factory = new ConnectionFactory();
|
||||
|
||||
_connection = _connectionFactory.CreateConnection();
|
||||
if (!string.IsNullOrEmpty(rabbitMQConfiguration.EndpointUri))
|
||||
{
|
||||
_factory.Endpoint = new AmqpTcpEndpoint(new Uri(rabbitMQConfiguration.EndpointUri));
|
||||
}
|
||||
else
|
||||
{
|
||||
_factory.HostName = rabbitMQConfiguration.HostName;
|
||||
_factory.UserName = rabbitMQConfiguration.UserName;
|
||||
_factory.Password = rabbitMQConfiguration.Password;
|
||||
_factory.Port = rabbitMQConfiguration.Port;
|
||||
_factory.VirtualHost = rabbitMQConfiguration.VirtualHost;
|
||||
}
|
||||
|
||||
if (rabbitMQConfiguration.EnableSsl)
|
||||
{
|
||||
_factory.Ssl = new SslOption
|
||||
{
|
||||
Enabled = rabbitMQConfiguration.EnableSsl,
|
||||
Version = SslProtocols.Tls12
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(rabbitMQConfiguration.SslCertPath))
|
||||
{
|
||||
_factory.Ssl.CertPath = rabbitMQConfiguration.SslCertPath;
|
||||
_factory.Ssl.ServerName = rabbitMQConfiguration.SslServerName;
|
||||
}
|
||||
}
|
||||
|
||||
_connection = _factory.CreateConnection();
|
||||
_consumerChannel = CreateConsumerChannel();
|
||||
|
||||
StartBasicConsume();
|
||||
@ -125,7 +150,7 @@ public class RabbitMQCache<T> : IDisposable, ICacheNotify<T> where T : IMessage<
|
||||
return;
|
||||
}
|
||||
|
||||
_connection = _connectionFactory.CreateConnection();
|
||||
_connection = _factory.CreateConnection();
|
||||
_connection.ConnectionShutdown += (s, e) => TryConnect();
|
||||
_connection.CallbackException += (s, e) => TryConnect();
|
||||
_connection.ConnectionBlocked += (s, e) => TryConnect();
|
||||
@ -214,5 +239,10 @@ public class RabbitMQSettings
|
||||
public string HostName { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
|
||||
public int Port { get; set; }
|
||||
public string VirtualHost { get; set; }
|
||||
public string EndpointUri { get; set; }
|
||||
public bool EnableSsl { get; set; }
|
||||
public string SslServerName { get; set; }
|
||||
public string SslCertPath { get; set; }
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
"RabbitMQ": {
|
||||
"Hostname": "localhost",
|
||||
"UserName": "guest",
|
||||
"Password": "guest"
|
||||
"Password": "guest",
|
||||
"Port": 5672,
|
||||
"VirtualHost": "/"
|
||||
}
|
||||
}
|
@ -2,6 +2,12 @@
|
||||
"RabbitMQ": {
|
||||
"Hostname": "localhost",
|
||||
"UserName": "guest",
|
||||
"Password": "guest"
|
||||
"Password": "guest",
|
||||
"Port": 5672,
|
||||
"VirtualHost": "/",
|
||||
"EndpointUri": "",
|
||||
"EnableSsl": false,
|
||||
"SslServerName": "",
|
||||
"SslCertPath": ""
|
||||
}
|
||||
}
|
@ -64,4 +64,4 @@ export * as Themes from "./themes";
|
||||
export { default as Portal } from "./portal";
|
||||
export { default as TableContainer } from "./table-container";
|
||||
export { default as Slider } from "./slider";
|
||||
export { default as Selector } from "./Selector";
|
||||
export { default as Selector } from "./selector";
|
||||
|
Loading…
Reference in New Issue
Block a user