Merge branch 'develop' into bugfix/fixed-closing-delete-user-dialog

This commit is contained in:
Alexey Safronov 2022-09-08 14:51:33 +03:00 committed by GitHub
commit 9a48bc19b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 80 additions and 26 deletions

View File

@ -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))
{
factory.UserName = settings.UserName;
}
if (!string.IsNullOrEmpty(settings.Password))
{
factory.Password = settings.Password;
};
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;
}
}
var retryCount = 5;

View File

@ -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
_factory = new ConnectionFactory();
if (!string.IsNullOrEmpty(rabbitMQConfiguration.EndpointUri))
{
HostName = rabbitMQConfiguration.HostName,
UserName = rabbitMQConfiguration.UserName,
Password = rabbitMQConfiguration.Password
};
_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 = _connectionFactory.CreateConnection();
_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();
@ -213,6 +238,11 @@ public class RabbitMQSettings
{
public string HostName { get; set; }
public string UserName { get; set; }
public string Password { 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; }
}

View File

@ -2,6 +2,8 @@
"RabbitMQ": {
"Hostname": "localhost",
"UserName": "guest",
"Password": "guest"
"Password": "guest",
"Port": 5672,
"VirtualHost": "/"
}
}

View File

@ -2,6 +2,12 @@
"RabbitMQ": {
"Hostname": "localhost",
"UserName": "guest",
"Password": "guest"
}
"Password": "guest",
"Port": 5672,
"VirtualHost": "/",
"EndpointUri": "",
"EnableSsl": false,
"SslServerName": "",
"SslCertPath": ""
}
}

View File

@ -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";