add consume register function
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Torma Kristóf 2020-07-06 23:02:44 +02:00
parent 23197e0ba8
commit c4f1c4f294
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
1 changed files with 13 additions and 1 deletions

View File

@ -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.