Update consumer.py

update reading configurations
This commit is contained in:
Jeniamakarchik
2020-02-07 12:03:07 +03:00
parent 258f3518bf
commit af6230d072

View File

@@ -1,6 +1,7 @@
import json
import os
from functools import partial
from pathlib import Path
from threading import Thread, active_count
import pika
@@ -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()