private static void Main(string[] args) { Task.Delay(20000).Wait(); // waiting for rabbit & sql // DataBaseService dataBaseService = new DataBaseService(); var kafkaProducerHostedService = new KafkaProducerHostedService(); var factory = new ConnectionFactory { HostName = "rabbitmq", Port = 5672 }; factory.UserName = "******"; factory.Password = "******"; var conn = factory.CreateConnection(); var channel = conn.CreateModel(); channel.QueueDeclare("przelew", false, false, false, null); var consumer = new EventingBasicConsumer(channel); Console.WriteLine("Consuming Queue Now"); consumer.Received += (model, ea) => { var body = ea.Body; try { var message = Encoding.UTF8.GetString(body); var msgSplit = message.Split("."); Console.Out.WriteLine("I'm putting message from: " + msgSplit[1] + " to kafka"); kafkaProducerHostedService.StartAsync(-int.Parse(msgSplit[3]), msgSplit[0], msgSplit[1], msgSplit[2]); } catch (Exception e) { Console.WriteLine(" [.] " + e.Message); var message = Encoding.UTF8.GetString(body).Split("."); } }; channel.BasicConsume("przelew", true, consumer); }
private static void Main(string[] args) { Task.Delay(30000).Wait(); // waiting for sql and kafka var kafkaProducerHostedService = new KafkaProducerHostedService(); var dataBaseService = new DataBaseService(); for (var i = 1; i < 1000; i++) { var amount = dataBaseService.Query(i.ToString()); var amountInt = new int(); if (amount != null && int.TryParse(amount, out amountInt)) { Console.WriteLine("Writing to kafka"); Console.WriteLine(amount); kafkaProducerHostedService.StartAsync(amountInt, "", i.ToString(), "0"); } else { Console.WriteLine($"Failed to init database with id {i}, amount: " + amount); } } }