How does Python RPC enable a single consumer to consume multiple queues?

The

problem is this: the client needs to send messages in five different message queues, and the server calls different functions after receiving messages in five queues.

I declare on the server that five queues are declared at the same time, but when listening to the five queues at the same time in the main thread, the remaining four queues are blocked and can only listen on one queue.

so I use multithreading to have each thread listen on a queue:

    def bind_exchange_to_queue(self,api_name):
        self.result = self.channel.queue_declare(queue=self.queue_name.format(api_name))
        self.channel.exchange_declare(
            exchange=self.exchange_name,
            exchange_type="topic",
            auto_delete=True,
        )
        self.channel.queue_bind(
            exchange = self.exchange_name,
            queue = self.queue_name.format(api_name),
            routing_key = self.routing_key.format(api_name)
        )
        self.channel.basic_consume(self.on_request, queue=self.queue_name.format(api_name))
        self.channel.start_consuming()
        
        ...
    def called(self):
    threads = []
    for api_name in self.api_name_list:
        t = threading.Thread(target=self.bind_exchange_to_queue, args=(api_name,))
        t.setDaemon(True)  -sharp 
        t.start()
        threads.append(t)
    self.channel.basic_consume(self.on_request,queue=self.queue_name.format(api_name))
    self.channel.start_consuming()

    t.join()

but report the following error:

is there any correct way to solve it?!

Feb.27,2021
Menu