mosquito / aio-pika

AMQP 0.9 client designed for asyncio and humans.
https://aio-pika.readthedocs.org/
Apache License 2.0
1.18k stars 186 forks source link

should I make a hard connection in my app? #462

Open yangjinhao1234 opened 2 years ago

yangjinhao1234 commented 2 years ago

I see the doc, I know the connection class is the beginning of the aio-pika. but I don't know if the connection is designed to be a reuseable one?

could I make a connection and reuse it anywhere like this ?

class publisher:
    _instance=None
    def __new__(cls):
        if not cls._instance:
            cls._instance=super().__new__(cls)
        return cls._instance

    async def initialize(url):
        self.__connection=aio-pika.connect(url)

    @property
    def connection():
        return self.__connection