import pika import pruebas.controller class BlockingConnectionAdapter(object): def __init__(self, controller, queue='test'): self.controller = controller self.connection = pika.BlockingConnection() self.channel = self.connection.channel() self.queue = self.channel.queue_declare(queue=queue, durable=True, exclusive=False, auto_delete=False) self.channel.basic_consume(self.on_message, queue=queue) def on_message(self, channel, method_frame, header_frame, body): print(method_frame.delivery_tag) print(body) print(channel.basic_ack(delivery_tag=method_frame.delivery_tag)) self.controller.handle_request(body) def start_service(self): print('Starting...') try: self.channel.start_consuming() except KeyBoardInterrupt: self.channel.stop_consuming() self.teardown() self.connection.close() def teardown(self): print('Tearing down...') if __name__ == '__main__': controller = pruebas.controller.FakeController() adapter = BlockingConnectionAdapter(controller) adapter.start_service()