#!/usr/bin/python3 import sys import os import pika import logging from asebat.timefmt import timestamp_fmt as ts from asebat.timefmt import date_refmt as df from asebat.config import set_config as setting def callback(ch, method, properties, body): #body รจ di tipo byte logging.info("PID {:>5} >> Read message {}".format( os.getpid(), body.decode("utf-8"))) ch.basic_ack(delivery_tag=method.delivery_tag) def main(): cfg = setting.config() logging.basicConfig( format="%(asctime)s %(message)s", filename="/var/log/" + cfg.elablog, level=logging.INFO, ) parameters = pika.URLParameters('amqp://' + cfg.mquser + ':' + cfg.mqpass + '@' + cfg.mqhost + ':5672/%2F') connection = pika.BlockingConnection(parameters) channel = connection.channel() channel.queue_declare(queue=cfg.csv_queue, durable=True) channel.basic_qos(prefetch_count=1) channel.basic_consume(queue=cfg.csv_queue, on_message_callback=callback) try: channel.start_consuming() except KeyboardInterrupt: logging.info("PID {:>5} >> Info: {}.".format( os.getpid(), "Shutdown requested...exiting")) if __name__ == "__main__": main()