protected override async Task ExecuteAsync(CancellationToken stoppingToken) { try { var channel = _connection.CreateModel(); _rabbitService.DeclareQueue(ref channel); var rand = new Random(); while (!stoppingToken.IsCancellationRequested) { await Task.Delay(1000, stoppingToken); var jsonCarro = JsonSerializer.Serialize(new Car { Brand = "Teste", Model = $"Ts {rand.Next(1, int.MaxValue)}" }); _rabbitService.CreateQueue(jsonCarro, ref channel); _logger.LogInformation($"Linha Criada: {jsonCarro}"); } } catch (Exception ex) { _logger.LogInformation($"ERRO NA CRIAÇÃO DA LINHA"); _logger.LogError($"ERRO:{ex.Message}", ex); throw; } }
private void ConsumerQueue() { var channel = _connection.CreateModel(); _rabbitService.DeclareQueue(ref channel); var consumer = _rabbitService.ConsumerQueue(ref channel); consumer.Received += (sender, response) => { var model = sender as EventingBasicConsumer; ProcessMessage(consumer.Model, response.Body, response.DeliveryTag); }; channel.BasicConsume(RabbitMQConfiguration.QueueName, false, consumer); }