so this is my code:
import asyncio
import logging
from asyncio import AbstractEventLoop
from aio_pika import connect, IncomingMessage
def test_one(a, b):
print("test_one", a, b)
class Consumer:
def __init__(self, url):
self.url = url
async def run(self, loop: AbstractEventLoop):
while True:
try:
connection = await connect(self.url, loop=loop)
connection.add_close_callback(test_one)
connection.add_close_callback(self.test_two)
# Creating a channel
channel = await connection.channel()
# Declaring queue
queue = await channel.declare_queue("snapshots")
logging.info("Started listening")
# Start listening the queue with name 'hello'
await queue.consume(self.on_message, no_ack=True)
break
except:
logging.error("Could not connect")
finally:
await asyncio.sleep(1)
def on_message(self, message: IncomingMessage):
print(message.body)
def test_two(self, a, b):
print("closed", a, b)
My problem is when I disconnect it only calls test_one function, but it doesn't call test_two function inside the class. I don't understand. I tried only adding the test_two function but that didn't work either. Tried removing the parameters. Same issue. I'm out of ideas. Do you know what I do wrong?
btw the self.on_message does work.