def consume_mails_per_hour(self):
        queue_manager = QueueManager(self.queue_service_url)
        queue_channel = queue_manager.channel()
        queue_channel.queue_declare(queue=QueueManager.QUEUE_NAME,
                                    arguments={'x-max-priority': 255})

        for i in range(0, self.mails_per_hour):
            method, properties, body = queue_channel.basic_get(
                QueueManager.QUEUE_NAME, auto_ack=True)
            if body is None:
                continue

            payload = QueuePayload(**json.loads(body))

            QUEUE_CONSUMER_BY_TEMPLATE.labels(payload.template.value).inc()
            QUEUE_CONSUMER_BY_PRIORITY.labels(properties.priority).inc()

            self.mail_manager.send_mail(payload.recipient, payload.mail_params,
                                        payload.template)
        queue_manager.close()
import json
import random
from os import environ

import pika

from producer.producer import Producer
from queue_manager import QueueManager

if __name__ == '__main__':
    QUEUE_SERVICE_URL = environ.get('QUEUE_SERVICE_URL',
                                    'amqp://*****:*****@localhost:5672/%2f')

    queue_manager = QueueManager(QUEUE_SERVICE_URL)

    channel = queue_manager.channel()
    channel.queue_declare(queue=QueueManager.QUEUE_NAME,
                          arguments={'x-max-priority': 255})

    parser = argparse.ArgumentParser('main_publisher')
    parser.add_argument('-n',
                        dest='number_of_messages',
                        default=1,
                        help='The number of messages to generate',
                        type=int)
    args = parser.parse_args()

    producer = Producer()
    for i in range(0, args.number_of_messages):
        template = random.randint(1, 5)
        if template == 1: