static void Main(string[] args) { Console.Title = "Recipient List"; BankEngine be = new BankEngine(); ConnectionFactory factory = new ConnectionFactory() { HostName = "datdb.cphbusiness.dk", UserName = "******", Password = "******" }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { channel.QueueDeclare(queue: QUEUE_NAME, durable: false, exclusive: false, autoDelete: false, arguments: null); channel.ExchangeDeclare(EXCHANGE_NAME, ExchangeType.Topic); channel.QueueBind(QUEUE_NAME, EXCHANGE_NAME, ""); Console.WriteLine(" RecipientList ready "); var consumer = new EventingBasicConsumer(channel); consumer.Received += (model, ea) => { var body = ea.Body; var message = Encoding.UTF8.GetString(body); string[] messageArray = message.Split('#'); string ssn = messageArray[0]; double amount = Convert.ToDouble(messageArray[1]); int duration = Convert.ToInt32(messageArray[2]); int creditScore = Convert.ToInt32(messageArray[3]); List <Bank> listBanks = JsonConvert.DeserializeObject <List <Bank> >(messageArray[4]); Console.WriteLine(" [x] Received {0}", "SSN:" + ssn + " AMOUNT:" + amount + " DURATION:" + duration + " CREDITSCORE:" + creditScore + " BANKS:{" + BankNamesToString(listBanks) + "}"); be.sendMessage("aggregatorList_exchange", ssn + "#" + messageArray[4], "Liste med " + listBanks.Count + " Bank Send To Aggregator "); foreach (Bank bank in listBanks) { string messageSend = ssn + "#" + amount + "#" + duration + "#" + creditScore + "#" + JsonConvert.SerializeObject(bank); string println = bank.Bankname; string routingKey = bank.TranslatorType; be.sendMessage("recipientList_exchange", messageSend, println, routingKey); } }; channel.BasicConsume(queue: QUEUE_NAME, autoAck: true, consumer: consumer); Console.WriteLine(" Press [enter] to exit."); Console.ReadLine(); } }
private static async void StartTimer() { await Task.Delay(TimeSpan.FromSeconds(10)); if (terminateTimer == false) { LoanResponse loanResponse; loanResponseMap.TryGetValue(currentSsn, out loanResponse); BankEngine be = new BankEngine(); string messageToSend = (loanResponse.FromBank != "!" ? currentSsn + "#" + loanResponse.FromBank + "#" + loanResponse.InterestRate : "No Banks Could Meet Your Wish"); be.sendMessage("loanResponse_exchange", messageToSend, messageToSend); loanResponseMap.Remove(currentSsn); } }
static void Main(string[] args) { Console.Title = "GetCreditScore"; BankEngine be = new BankEngine(); ConnectionFactory factory = new ConnectionFactory() { HostName = "datdb.cphbusiness.dk", UserName = "******", Password = "******" }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { channel.QueueDeclare(queue: QUEUE_NAME, durable: false, exclusive: false, autoDelete: false, arguments: null); channel.ExchangeDeclare(EXCHANGE_NAME, ExchangeType.Topic); channel.QueueBind(QUEUE_NAME, EXCHANGE_NAME, ""); Console.WriteLine(" GetCreditScore ready "); var consumer = new EventingBasicConsumer(channel); consumer.Received += (model, ea) => { var body = ea.Body; var message = Encoding.UTF8.GetString(body); string[] messageArray = message.Split('#'); string ssn = messageArray[0]; double amount = Convert.ToDouble(messageArray[1]); int duration = Convert.ToInt32(messageArray[2]); Console.WriteLine(" [x] Received {0}", "SSN:" + ssn + " AMOUNT:" + amount + " DURATION:" + duration); int creditScore = GetCreditScore(ssn); string messageToSend = ssn + "#" + amount + "#" + duration + "#" + creditScore; string println = "SSN:" + ssn + " AMOUNT:" + amount + " DURATION:" + duration + " CREDITSCORE:" + creditScore; be.sendMessage("creditScore_exchange", messageToSend, println); }; channel.BasicConsume(queue: QUEUE_NAME, autoAck: true, consumer: consumer); Console.WriteLine(" Press [enter] to exit."); Console.ReadLine(); } }
static void Main(string[] args) { listBanks = new List <Bank>(); Console.Title = "Aggregator"; ConnectionFactory factory = new ConnectionFactory() { HostName = "datdb.cphbusiness.dk", UserName = "******", Password = "******" }; using (var connection = factory.CreateConnection()) using (var channel1 = connection.CreateModel()) using (var channel2 = connection.CreateModel()) { channel1.QueueDeclare(queue: "aggregatorList_queue", durable: false, exclusive: false, autoDelete: false, arguments: null); channel1.ExchangeDeclare("aggregatorList_exchange", ExchangeType.Topic); channel1.QueueBind("aggregatorList_queue", "aggregatorList_exchange", ""); channel2.QueueDeclare(queue: "aggregator_queue", durable: false, exclusive: false, autoDelete: false, arguments: null); channel2.ExchangeDeclare("aggregator_exchange", ExchangeType.Topic); channel2.QueueBind("aggregator_queue", "aggregator_exchange", ""); Console.WriteLine(" Aggregator ready "); var consumer1 = new EventingBasicConsumer(channel1); consumer1.Received += (model, ea) => { var body = ea.Body; var message = Encoding.UTF8.GetString(body); string[] messageArray = message.Split('#'); currentSsn = messageArray[0]; listBanks.Clear(); listBanks = JsonConvert.DeserializeObject <List <Bank> >(messageArray[1]); Console.WriteLine(" [x] Received {0}", listBanks.Count + " banks"); loanResponseMap.Add(currentSsn, new LoanResponse(100.0, "!")); StartTimer(); }; channel1.BasicConsume(queue: "aggregatorList_queue", autoAck: true, consumer: consumer1); var consumer2 = new EventingBasicConsumer(channel2); consumer2.Received += (model, ea) => { var body = ea.Body; var message = Encoding.UTF8.GetString(body); string[] messageArray = message.Split('#'); string ssn = messageArray[0]; double interestRate = Convert.ToDouble(messageArray[1]); string correlationId = ea.BasicProperties.CorrelationId; Console.WriteLine(" [x] Received {0}", message); if (currentSsn == ssn) { LoanResponse loanResponse; loanResponseMap.TryGetValue(ssn, out loanResponse); if (loanResponse != null) { if (loanResponse.InterestRate > interestRate) { loanResponse.InterestRate = interestRate; loanResponse.FromBank = listBanks.Find(x => x.Normalizer.Contains(correlationId)).Bankname; } loanResponse.Counter++; loanResponseMap[ssn] = loanResponse; if (loanResponse.Counter == listBanks.Count) { terminateTimer = true; BankEngine be = new BankEngine(); string messageToSend = currentSsn + "#" + loanResponse.FromBank + "#" + loanResponse.InterestRate; be.sendMessage("loanResponse_exchange", messageToSend, messageToSend); loanResponseMap.Remove(currentSsn); } } } }; channel2.BasicConsume(queue: "aggregator_queue", autoAck: true, consumer: consumer2); Console.WriteLine(" Press [enter] to exit."); Console.ReadLine(); } }