#!/usr/bin/env python3 # This file is part of Cockpit. # # Copyright (C) 2018 Red Hat, Inc. # # Cockpit is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # Cockpit is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with Cockpit; If not, see . MAX_PRIORITY = 9 import argparse import sys from task import distributed_queue def main(): parser = argparse.ArgumentParser(description='Read and print messages from the queue without acknowleding them') parser.add_argument('--amqp', default='localhost:5671', help='The host:port of the AMQP server to consume from (default: %(default)s)') opts = parser.parse_args() with distributed_queue.DistributedQueue(opts.amqp, ['public', 'rhel'], passive=True) as q: def print_queue(queue): if q.declare_results[queue] is None: print("queue {} does not exist".format(queue)) return message_count = q.declare_results[queue].method.message_count if message_count == 0: print("queue {} is empty".format(queue)) return for i in range(message_count): method_frame, header_frame, body = q.channel.basic_get(queue=queue) if method_frame: print(body.decode()) print('public queue:') print_queue('public') print('rhel queue:') print_queue('rhel') if __name__ == '__main__': sys.exit(main())