diff --git a/src/flask_rabbit_broker.py b/src/flask_rabbit_broker.py index 01fcc6a..e85a61a 100644 --- a/src/flask_rabbit_broker.py +++ b/src/flask_rabbit_broker.py @@ -27,6 +27,7 @@ class FlaskRabbitBroker: self.routing_key = None self.connection = None self.channel = None + self.exchange = None def init_app(self, app) -> None: """ @@ -64,13 +65,24 @@ class FlaskRabbitBroker: """ channel = self.connection.channel() try: - channel.exchange_declare(exchange=self.exchange_name, + exchange = channel.exchange_declare(exchange=self.exchange_name, exchange_type='fanout', durable=True, auto_delete=False) finally: channel.close() + def register_callback(self, callback) -> None: + """ + Register a callback. + :param callback: + :return: + """ + channel = self.connection.channel() + queue = channel.queue_declare(durable=True, auto_delete=False) + queue.bind(self.exchange) + queue.basic_consume(callback, no_ack=True) + def send(self, message: str) -> None: """ Sends a message to the declared exchange.