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.routing_key = None
|
||||||
self.connection = None
|
self.connection = None
|
||||||
self.channel = None
|
self.channel = None
|
||||||
|
self.exchange = None
|
||||||
|
|
||||||
def init_app(self, app) -> None:
|
def init_app(self, app) -> None:
|
||||||
"""
|
"""
|
||||||
@ -64,13 +65,24 @@ class FlaskRabbitBroker:
|
|||||||
"""
|
"""
|
||||||
channel = self.connection.channel()
|
channel = self.connection.channel()
|
||||||
try:
|
try:
|
||||||
channel.exchange_declare(exchange=self.exchange_name,
|
exchange = channel.exchange_declare(exchange=self.exchange_name,
|
||||||
exchange_type='fanout',
|
exchange_type='fanout',
|
||||||
durable=True,
|
durable=True,
|
||||||
auto_delete=False)
|
auto_delete=False)
|
||||||
finally:
|
finally:
|
||||||
channel.close()
|
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:
|
def send(self, message: str) -> None:
|
||||||
"""
|
"""
|
||||||
Sends a message to the declared exchange.
|
Sends a message to the declared exchange.
|
||||||
|
Loading…
Reference in New Issue
Block a user