As it turned out, my understanding of AMQP was incomplete.
The idea is as follows:
Client
After receiving the connection, the client should not care about anything other than the exchange name and the routing key. That is, we do not know in which queue this will end.
channel.basic_publish(exchange='order', routing_key="order.test.customer", body=pickle.dumps(data), properties=pika.BasicProperties( content_type="text/plain", delivery_mode=2))
Consumer
When the channel is open, we announce the exchange and queue
channel.exchange_declare(exchange='order', type="topic", durable=True, auto_delete=False) channel.queue_declare(queue="test", durable=True, exclusive=False, auto_delete=False, callback=on_queue_declared)
When the queue is ready, this is a good place in the on_queue_declared callback, we can bind the queue to the exchange using our desired routing key.
channel.queue_bind(queue='test', exchange='order', routing_key='order.test.customer')
Messages sent to the "order" exchange with the routing key, "order.test.customer" will now be redirected to the "test" queue, where the consumer can pick it up.
Simon source share