From af6230d072168960cb75a085de9e62cb87b9946b Mon Sep 17 00:00:00 2001 From: Jeniamakarchik Date: Fri, 7 Feb 2020 12:03:07 +0300 Subject: [PATCH] Update consumer.py update reading configurations --- src/consumer.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/consumer.py b/src/consumer.py index da145b5..efd2f10 100644 --- a/src/consumer.py +++ b/src/consumer.py @@ -1,6 +1,7 @@ import json import os from functools import partial +from pathlib import Path from threading import Thread, active_count import pika @@ -26,7 +27,7 @@ def callback(ch, method, properties, body, access): 'book_id': data['id'], 'access': access } - + thread = Thread(target=convert_book, kwargs=params) thread.start() print(f'Active threads: {active_count()}.') @@ -42,13 +43,16 @@ def callback(ch, method, properties, body, access): if __name__ == '__main__': folder_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - config_path = os.path.join(folder_path, "config/config.json") - # config_path = os.path.join(folder_path, "config/queue_config.json") + # config_path = Path(os.path.join(folder_path, "config/config.json")) + config_path = Path(os.path.join(folder_path, "config/queue_config.json")) with open(config_path, "r") as f: conf_param = json.load(f) + host = conf_param.get('host') or pika.ConnectionParameters().DEFAULT_HOST + port = conf_param.get('port') or pika.ConnectionParameters().DEFAULT_PORT + credentials = pika.PlainCredentials(username=conf_param['username'], password=conf_param['password']) - parameters = pika.ConnectionParameters(host=conf_param['host'], credentials=credentials) + parameters = pika.ConnectionParameters(host=host, port=port, credentials=credentials) connection = pika.BlockingConnection(parameters) channel = connection.channel()