Very grateful for your time to prepare such a thorough response. It helped greatly.
For any interested, here is the server code:
#
# server.py
# - a client will send us "Marco" and we will send back "Polo"
# the goal is to use reply-to
import pika
SERVER_QUEUE = 'rpc.server.queue'
def on_recv_req(ch, method, properties, body):
print(body)
ch.basic_publish(exchange='', routing_key=properties.reply_to, body='Polo')
if __name__=='__main__':
conn = pika.BlockingConnection(pika.ConnectionParameters(host='172.17.0.2'))
ch = conn.channel()
# declare a queue
ch.queue_declare(queue=SERVER_QUEUE, exclusive=True, auto_delete=True)
ch.basic_consume(on_recv_req, queue=SERVER_QUEUE)
ch.start_consuming()
And the client code:
#
# client.py
# - send "Marco" to the direct reply-to channel
import pika
SERVER_QUEUE='rpc.server.queue'
def on_recv_resp(ch, method, properties, body):
print(body)
if __name__ == '__main__':
conn = pika.BlockingConnection(pika.ConnectionParameters(host='172.17.0.2'))
ch = conn.channel()
ch.basic_consume(on_recv_resp, queue='amq.rabbitmq.reply-to', no_ack=True)
ch.basic_publish(exchange='', routing_key=SERVER_QUEUE, body='Marco', properties=pika.BasicProperties(reply_to='amq.rabbitmq.reply-to'))
ch.start_consuming()
This works perfectly, and again am very grateful for your help.
Best,
-MS