#!/usr/bin/env python import logging from pika import BlockingConnection, ConnectionParameters if __name__ == '__main__': logging.basicConfig(level=logging.INFO) # setting up rabbitmq pubsub with BlockingConnection(ConnectionParameters('localhost')) as rabbit_conn: with rabbit_conn.channel() as rabbit_chan: rabbit_channel.queue_declare(queue="my_queue") def message_callback(ch, method, properties, body): logging.info("Got message '%s'" % body) rabbit_channel.basic_consume(message_callback, queue="my_queue", no_ack=True) # listen for items logging.info("Listen for items ...") rabbit_channel.start_consuming()