Created
August 11, 2015 00:31
-
-
Save fespino/eae6d241e53d5a20aa3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment