static void Main(string[] args) { Configuration = Utils.Configure(); RegisterServices(Configuration); var factory = new ConnectionFactory() { HostName = rabbitMQConfig.HostName, UserName = rabbitMQConfig.UserName, Password = rabbitMQConfig.Password }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { channel.QueueDeclare(rabbitMQConfig.QueueName, true, false, false, null); channel.BasicQos(0, UnackedMessagesPerConsumer, false); var consumer = new EventingBasicConsumer(channel); consumer.Received += async(model, ea) => { var body = ea.Body; var message = Utils.Deserialize <Message>(body); Console.WriteLine(" [x] Received {0}", message); // build a point and save to Influx PointMeasure point = BuildPoint(message); await influxDb.WriteAsync(point); using (var dbContext = new ApplicationDbContext(dbOptions.Options)) { var alertService = new AlertService(dbContext, serviceProvider.GetService <IAlertNotifier>()); // check alerts await alertService.CheckAlerts(message); } channel.BasicAck(ea.DeliveryTag, false); }; channel.BasicConsume(rabbitMQConfig.QueueName, false, consumer); Console.WriteLine(" Press [enter] to exit."); Console.ReadLine(); } DisposeServices(); }