diff --git a/Birdmap.API/Startup.cs b/Birdmap.API/Startup.cs index 3db4a85..8a789c0 100644 --- a/Birdmap.API/Startup.cs +++ b/Birdmap.API/Startup.cs @@ -95,11 +95,9 @@ namespace Birdmap.API app.UseOpenApi(); app.UseSwaggerUi3(); - app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseSpaStaticFiles(); - app.UseAuthentication(); app.UseRouting(); app.UseAuthorization(); diff --git a/Birdmap.API/appsettings.json b/Birdmap.API/appsettings.json index 389cfb2..dd787b4 100644 --- a/Birdmap.API/appsettings.json +++ b/Birdmap.API/appsettings.json @@ -27,10 +27,25 @@ "UseRabbitMq": false, "Mqtt": { "BrokerHostSettings": { + "VirtualHost": "", "Host": "", "Port": 1883 }, + "ExchangeSettings": { + "Name": "", + "Type": "", + "Durable": false, + "AutoDelete": false + }, + + "QueueSettings": { + "Name": "", + "Durable": false, + "Exclusive": false, + "AutoDelete": false + }, + "ClientSettings": { "Id": "ASP.NET Core client", "Username": "", diff --git a/Birdmap.BLL/Options/RabbitMqClientOptions.cs b/Birdmap.BLL/Options/RabbitMqClientOptions.cs index 7e5ea54..520194d 100644 --- a/Birdmap.BLL/Options/RabbitMqClientOptions.cs +++ b/Birdmap.BLL/Options/RabbitMqClientOptions.cs @@ -1,4 +1,11 @@ namespace Birdmap.BLL.Options { - public record RabbitMqClientOptions(string Hostname, int Port, string Username, string Password, string Topic); + public record RabbitMqClientOptions( + 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); } diff --git a/Birdmap.BLL/Services/CommunationServices/RabbitMq/RabbitMqClientService.cs b/Birdmap.BLL/Services/CommunationServices/RabbitMq/RabbitMqClientService.cs index 800a0a2..b20818e 100644 --- a/Birdmap.BLL/Services/CommunationServices/RabbitMq/RabbitMqClientService.cs +++ b/Birdmap.BLL/Services/CommunationServices/RabbitMq/RabbitMqClientService.cs @@ -17,14 +17,14 @@ namespace Birdmap.BLL.Services.CommunationServices.RabbitMq private IConnection _connection; private IModel _channel; private readonly IConnectionFactory _factory; - private readonly string _topic; + private readonly RabbitMqClientOptions _options; public override bool IsConnected => throw new NotImplementedException(); public RabbitMqClientService(RabbitMqClientOptions options, ILogger logger, IInputService inputService, IHubContext hubContext) : base(logger, inputService, hubContext) { - _topic = options.Topic; + _options = options; _factory = new ConnectionFactory() { HostName = options.Hostname, @@ -85,17 +85,26 @@ namespace Birdmap.BLL.Services.CommunationServices.RabbitMq _connection = _factory.CreateConnection(); _channel = _connection.CreateModel(); - _channel.ExchangeDeclare(exchange: "topic_logs", type: "topic"); - var queueName = _channel.QueueDeclare().QueueName; + _channel.ExchangeDeclare( + exchange: _options.ExchangeName, + type: _options.ExchangeType, + durable: _options.ExchangeDurable, + autoDelete: _options.ExchangeAutoDelete); - _channel.QueueBind(queue: queueName, - exchange: "topic_logs", - routingKey: _topic); + _channel.QueueDeclare( + queue: _options.QueueName, + durable: _options.QueueDurable, + exclusive: _options.QueueExclusive, + autoDelete: _options.QueueAutoDelete); + + _channel.QueueBind(queue: _options.QueueName, + exchange: _options.ExchangeName, + routingKey: _options.Topic); var consumer = new AsyncEventingBasicConsumer(_channel); consumer.Received += OnRecieved; - _channel.BasicConsume(queue: queueName, + _channel.BasicConsume(queue: _options.QueueName, autoAck: true, consumer: consumer); diff --git a/Birdmap.BLL/Startup.cs b/Birdmap.BLL/Startup.cs index 3af31a0..98c58dc 100644 --- a/Birdmap.BLL/Startup.cs +++ b/Birdmap.BLL/Startup.cs @@ -61,6 +61,25 @@ namespace Birdmap.BLL { Host = brokerHost.GetValue("Host"), Port = brokerHost.GetValue("Port"), + VirtualHost = brokerHost.GetValue("VirtualHost"), + }; + + var exchange = mqtt.GetSection("ExchangeSettings"); + var exchangeSettings = new + { + Name = exchange.GetValue("Name"), + Type = exchange.GetValue("Type"), + Durable = exchange.GetValue("Durable"), + AutoDelete = exchange.GetValue("AutoDelete"), + }; + + var queue = mqtt.GetSection("QueueSettings"); + var queueSettings = new + { + Name = queue.GetValue("Name"), + Durable = exchange.GetValue("Durable"), + Exclusive = exchange.GetValue("Exclusive"), + AutoDelete = exchange.GetValue("AutoDelete"), }; if (configuration.GetValue("UseRabbitMq")) @@ -68,8 +87,17 @@ namespace Birdmap.BLL services.AddRabbitMqClientServiceWithConfig(new RabbitMqClientOptions( Hostname: brokerHostSettings.Host, Port: brokerHostSettings.Port, + VirtualHost: brokerHostSettings.VirtualHost, Username: clientSettings.Username, 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)); } else diff --git a/docker-compose.yml b/docker-compose.yml index 989849f..d117814 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -41,6 +41,15 @@ services: - Birdmap_UseRabbitMq=false - Birdmap_Mqtt__BrokerHostSettings__Host=localhost - 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__Username=username - Birdmap_Mqtt__ClientSettings__Password=password