""" Handles results from banks passing a message in internal message format to aggregation service. """ from rmqConsume import Consumer from rmqPublish import publish_to_q from queue_names import * from json import dumps import translators as tr def callback(ch, method, properties, body): print "raw bank response body:", body mtype = properties.correlation_id[8:] mid = properties.correlation_id[:8] properties.correlation_id = mid message = tr.loads(body, mtype) message["type"] = mtype publish_to_q("localhost", AGGREGATOR_QUEUE, dumps(message), properties) consumer = Consumer("datdb.cphbusiness.dk", NORMALIZER_QUEUE) consumer.on_receive = callback consumer.consume()
from rmqConsume import Consumer from rmqPublish import publish_to_q from queue_names import * from json import loads, dumps import translators as tr import random def callback(ch, method, properties, body): properties.correlation_id += "bdo" properties.reply_to = NORMALIZER_QUEUE m = loads(body) print "BDO: ", m #pretend to get a response, send to normalizer m = loads(tr.dumps(m, "bdo")) del m['loanAmount'] del m['loanDuration'] rating = random.randint(2, 50) m["interestRate"] = rating print m publish_to_q("datdb.cphbusiness.dk", NORMALIZER_QUEUE, dumps(m), properties) consumer = Consumer("localhost", BDO_TRANSLATOR_QUEUE) consumer.on_receive = callback consumer.consume()
"nytkredit": NYTKREDIT_TRANSLATOR_QUEUE, "bdo": BDO_TRANSLATOR_QUEUE, } awaiting = {} def callback(ch, method, properties, body): global awaiting print "for aggregator:", body m = loads(body) #empty container, awaiting messages from banks if m["type"] == "await": awaiting[m["await_id"]] = {"banks": m["banks"]} else: #add message to container by message type entry = awaiting[properties.correlation_id] entry[m["type"]] = m entry["banks"].remove(type_to_bank[m["type"]]) if len(entry["banks"]) == 0: del entry["banks"] result = {"rates": {}} for k, v in entry.iteritems(): result["ssn"] = v["ssn"] result["rates"][v["type"]] = v["interest"] print "end result:", result consumer = Consumer("localhost", AGGREGATOR_QUEUE) consumer.on_receive = callback consumer.consume()
in the given timeframe. """ from rulebase import RuleBase from rmqConsume import Consumer from rmqPublish import publish_to_q from queue_names import * from json import loads, dumps import requests TRANSLATORS = [ DANSKEBANK_TRANSLATOR_QUEUE, NORDEA_TRANSLATOR_QUEUE, NYTKREDIT_TRANSLATOR_QUEUE, BDO_TRANSLATOR_QUEUE, ] def callback(ch, method, properties, body): m = loads(body) res = loads(body) del res["banks"] final_message = dumps(res) print "received message", body, "sending to", len(m["banks"]) for t in TRANSLATORS: if t in m["banks"]: publish_to_q("localhost", t, final_message, properties) consumer = Consumer("localhost", RECIPIENT_LIST_QUEUE) consumer.on_receive = callback consumer.consume()
""" Node that receives initial message and enriches it with a credit from the credit score service. """ from rmqConsume import Consumer from rmqPublish import publish_to_q from creditapi import getCreditScore from queue_names import * from json import loads, dumps def callback(ch, method, properties, body): m = loads(body) print "getting credit score for:", body score = getCreditScore(m['ssn']) print "got credit score:", score m['score'] = str(score) publish_to_q("localhost", BANK_ENRICHER_QUEUE, dumps(m), properties) consumer = Consumer("localhost", CREDIT_ENRICHER_QUEUE) consumer.on_receive = callback consumer.consume()