Added new rabbitmq configs
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
2021-01-17 16:45:11 +01:00
parent 20a4b4d349
commit e9ffe514dd
6 changed files with 77 additions and 11 deletions

View File

@ -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<RabbitMqClientService> logger, IInputService inputService, IHubContext<DevicesHub, IDevicesHubClient> 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);