Compare commits

..

No commits in common. "89a416ac38099b5acb53d017c2173d121ff9e1ea" and "6a579772dff8ca0b4fcc35d8aa7a57ea539e82c6" have entirely different histories.

6 changed files with 11 additions and 77 deletions

View File

@ -95,9 +95,11 @@ namespace Birdmap.API
app.UseOpenApi(); app.UseOpenApi();
app.UseSwaggerUi3(); app.UseSwaggerUi3();
app.UseHttpsRedirection();
app.UseStaticFiles(); app.UseStaticFiles();
app.UseSpaStaticFiles(); app.UseSpaStaticFiles();
app.UseAuthentication(); app.UseAuthentication();
app.UseRouting(); app.UseRouting();
app.UseAuthorization(); app.UseAuthorization();

View File

@ -27,25 +27,10 @@
"UseRabbitMq": false, "UseRabbitMq": false,
"Mqtt": { "Mqtt": {
"BrokerHostSettings": { "BrokerHostSettings": {
"VirtualHost": "",
"Host": "", "Host": "",
"Port": 1883 "Port": 1883
}, },
"ExchangeSettings": {
"Name": "",
"Type": "",
"Durable": false,
"AutoDelete": false
},
"QueueSettings": {
"Name": "",
"Durable": false,
"Exclusive": false,
"AutoDelete": false
},
"ClientSettings": { "ClientSettings": {
"Id": "ASP.NET Core client", "Id": "ASP.NET Core client",
"Username": "", "Username": "",

View File

@ -1,11 +1,4 @@
namespace Birdmap.BLL.Options namespace Birdmap.BLL.Options
{ {
public record RabbitMqClientOptions( public record RabbitMqClientOptions(string Hostname, int Port, string Username, string Password, string Topic);
string Hostname, int Port, string VirtualHost,
string Username, string Password,
string ExchangeName, string ExchangeType,
bool ExchangeDurable, bool ExchangeAutoDelete,
string QueueName,
bool QueueDurable, bool QueueAutoDelete, bool QueueExclusive,
string Topic);
} }

View File

@ -17,14 +17,14 @@ namespace Birdmap.BLL.Services.CommunationServices.RabbitMq
private IConnection _connection; private IConnection _connection;
private IModel _channel; private IModel _channel;
private readonly IConnectionFactory _factory; private readonly IConnectionFactory _factory;
private readonly RabbitMqClientOptions _options; private readonly string _topic;
public override bool IsConnected => throw new NotImplementedException(); public override bool IsConnected => throw new NotImplementedException();
public RabbitMqClientService(RabbitMqClientOptions options, ILogger<RabbitMqClientService> logger, IInputService inputService, IHubContext<DevicesHub, IDevicesHubClient> hubContext) public RabbitMqClientService(RabbitMqClientOptions options, ILogger<RabbitMqClientService> logger, IInputService inputService, IHubContext<DevicesHub, IDevicesHubClient> hubContext)
: base(logger, inputService, hubContext) : base(logger, inputService, hubContext)
{ {
_options = options; _topic = options.Topic;
_factory = new ConnectionFactory() _factory = new ConnectionFactory()
{ {
HostName = options.Hostname, HostName = options.Hostname,
@ -85,26 +85,17 @@ namespace Birdmap.BLL.Services.CommunationServices.RabbitMq
_connection = _factory.CreateConnection(); _connection = _factory.CreateConnection();
_channel = _connection.CreateModel(); _channel = _connection.CreateModel();
_channel.ExchangeDeclare( _channel.ExchangeDeclare(exchange: "topic_logs", type: "topic");
exchange: _options.ExchangeName, var queueName = _channel.QueueDeclare().QueueName;
type: _options.ExchangeType,
durable: _options.ExchangeDurable,
autoDelete: _options.ExchangeAutoDelete);
_channel.QueueDeclare( _channel.QueueBind(queue: queueName,
queue: _options.QueueName, exchange: "topic_logs",
durable: _options.QueueDurable, routingKey: _topic);
exclusive: _options.QueueExclusive,
autoDelete: _options.QueueAutoDelete);
_channel.QueueBind(queue: _options.QueueName,
exchange: _options.ExchangeName,
routingKey: _options.Topic);
var consumer = new AsyncEventingBasicConsumer(_channel); var consumer = new AsyncEventingBasicConsumer(_channel);
consumer.Received += OnRecieved; consumer.Received += OnRecieved;
_channel.BasicConsume(queue: _options.QueueName, _channel.BasicConsume(queue: queueName,
autoAck: true, autoAck: true,
consumer: consumer); consumer: consumer);

View File

@ -61,25 +61,6 @@ namespace Birdmap.BLL
{ {
Host = brokerHost.GetValue<string>("Host"), Host = brokerHost.GetValue<string>("Host"),
Port = brokerHost.GetValue<int>("Port"), Port = brokerHost.GetValue<int>("Port"),
VirtualHost = brokerHost.GetValue<string>("VirtualHost"),
};
var exchange = mqtt.GetSection("ExchangeSettings");
var exchangeSettings = new
{
Name = exchange.GetValue<string>("Name"),
Type = exchange.GetValue<string>("Type"),
Durable = exchange.GetValue<bool>("Durable"),
AutoDelete = exchange.GetValue<bool>("AutoDelete"),
};
var queue = mqtt.GetSection("QueueSettings");
var queueSettings = new
{
Name = queue.GetValue<string>("Name"),
Durable = exchange.GetValue<bool>("Durable"),
Exclusive = exchange.GetValue<bool>("Exclusive"),
AutoDelete = exchange.GetValue<bool>("AutoDelete"),
}; };
if (configuration.GetValue<bool>("UseRabbitMq")) if (configuration.GetValue<bool>("UseRabbitMq"))
@ -87,17 +68,8 @@ namespace Birdmap.BLL
services.AddRabbitMqClientServiceWithConfig(new RabbitMqClientOptions( services.AddRabbitMqClientServiceWithConfig(new RabbitMqClientOptions(
Hostname: brokerHostSettings.Host, Hostname: brokerHostSettings.Host,
Port: brokerHostSettings.Port, Port: brokerHostSettings.Port,
VirtualHost: brokerHostSettings.VirtualHost,
Username: clientSettings.Username, Username: clientSettings.Username,
Password: clientSettings.Password, Password: clientSettings.Password,
ExchangeName: exchangeSettings.Name,
ExchangeType: exchangeSettings.Type,
ExchangeDurable: exchangeSettings.Durable,
ExchangeAutoDelete: exchangeSettings.AutoDelete,
QueueName: queueSettings.Name,
QueueDurable: queueSettings.Durable,
QueueExclusive: queueSettings.Exclusive,
QueueAutoDelete: queueSettings.AutoDelete,
Topic: clientSettings.Topic)); Topic: clientSettings.Topic));
} }
else else

View File

@ -41,15 +41,6 @@ services:
- Birdmap_UseRabbitMq=false - Birdmap_UseRabbitMq=false
- Birdmap_Mqtt__BrokerHostSettings__Host=localhost - Birdmap_Mqtt__BrokerHostSettings__Host=localhost
- Birdmap_Mqtt__BrokerHostSettings__Port=1883 - Birdmap_Mqtt__BrokerHostSettings__Port=1883
- Birdmap_Mqtt__BrokerHostSettings__VirtualHost=/
- Birdmap_Mqtt__ExchangeSettings__Name=birbmapexchange
- Birdmap_Mqtt__ExchangeSettings__Type=fanout
- Birdmap_Mqtt__ExchangeSettings__Durable=true
- Birdmap_Mqtt__ExchangeSettings__AutoDelete=true
- Birdmap_Mqtt__QueueSettings__Name=birbmapqueue
- Birdmap_Mqtt__QueueSettings__Durable=true
- Birdmap_Mqtt__QueueSettings__Exclusive=true
- Birdmap_Mqtt__QueueSettings__AutoDelete=true
- Birdmap_Mqtt__ClientSettings__Id=ASP.NET Core client - Birdmap_Mqtt__ClientSettings__Id=ASP.NET Core client
- Birdmap_Mqtt__ClientSettings__Username=username - Birdmap_Mqtt__ClientSettings__Username=username
- Birdmap_Mqtt__ClientSettings__Password=password - Birdmap_Mqtt__ClientSettings__Password=password