def create_app(): app = create_app_with_swagger() configure_log(app, __name__) configure_docdb(app) register_transaction_request_generator(app) configure_producer(app, 'info', 'call-event.tx', 'get-info') configure_producer(app, 'call_event', 'call-event.tx', 'call-event') configure_producer(app, 'bill_event', 'bill-event.tx', 'bill-close') return app
from phone_bills.billingcommon.logging import configure_log from phone_bills.billingcommon.dispatcher import message_dispatcher from phone_bills.billingmq.consumer import QueueHandler, BillingConsumers class Logger: pass logger = Logger() configure_log(logger, __name__) def on_message(body, message): logger.log.info(f'Consumers setup test.') logger.log.info(f'Message: {message}.') logger.log.info(f'Payload: {body}.') logger.log.info(f'Headers: {message.headers}\nBody: {body}.') def run(): queue_handlers = [ QueueHandler('call-event.tx', 'call-event', message_dispatcher.phone_call), QueueHandler('bill-event.tx', 'bill-close', message_dispatcher.bill_close), QueueHandler('call-event.tx', 'get-info', on_message) ] BillingConsumers(queue_handlers).run()
def __init__(self, db): self.db = db configure_log(self, PriceEngine.__name__)
def __init__(self, exchange_name, routing_key, on_message_callback, content_type='application/json'): exchange = self.declare_exchange(exchange_name) self.queue = Queue(exchange=exchange, routing_key=routing_key, auto_delete=True) self.on_message_callback = on_message_callback self.content_type = content_type configure_log(self, __name__)
def __init__(self, db, doc_db): self.db = db self.doc_db = doc_db self.price_engine = PriceEngine(self.db) configure_log(self, BillingService.__name__)
def __init__(self, db): self.db = db self.parser = CallRecordParser() self.price_engine = PriceEngine(self.db) configure_log(self, PhoneCallService.__name__)