add consume register function
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
23197e0ba8
commit
c4f1c4f294
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user