0
0
RabbitMQdevops~10 mins

Why RPC enables request-reply over queues in RabbitMQ - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a queue named 'rpc_queue' in RabbitMQ.

RabbitMQ
channel.queue_declare(queue='[1]')
Drag options to blanks, or click blank then click option'
Arpc_queue
Btask_queue
Crequest_queue
Dreply_queue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a queue name unrelated to RPC like 'task_queue'.
2fill in blank
medium

Complete the code to send a message with a unique correlation_id for RPC.

RabbitMQ
channel.basic_publish(exchange='', routing_key='rpc_queue', properties=pika.BasicProperties(correlation_id='[1]'), body='Hello')
Drag options to blanks, or click blank then click option'
Areply_to
Bcorrelation_id
C12345
Dunique_id_1
Attempts:
3 left
💡 Hint
Common Mistakes
Using the literal string 'correlation_id' instead of a unique ID.
3fill in blank
hard

Fix the error in the code to consume replies from the reply queue using the correct queue name.

RabbitMQ
channel.basic_consume(queue='[1]', on_message_callback=on_response, auto_ack=True)
Drag options to blanks, or click blank then click option'
Arpc_queue
Breply_queue
Ctask_queue
Drequest_queue
Attempts:
3 left
💡 Hint
Common Mistakes
Using the request queue name instead of the reply queue.
4fill in blank
hard

Fill both blanks to set the reply_to property and correlation_id in the RPC request message.

RabbitMQ
properties = pika.BasicProperties(reply_to='[1]', correlation_id='[2]')
Drag options to blanks, or click blank then click option'
Acallback_queue
Bunique_correlation_id
Crpc_queue
Dresponse_queue
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the reply_to queue name with the request queue name.
5fill in blank
hard

Fill all three blanks to complete the RPC server callback function that sends a reply with the same correlation_id.

RabbitMQ
def on_request(ch, method, props, body):
    response = body.decode().upper()
    ch.basic_publish(exchange='', routing_key=props.[1], properties=pika.BasicProperties(correlation_id=props.[2]), body=response)
    ch.basic_ack(delivery_tag=method.[3])
Drag options to blanks, or click blank then click option'
Areply_to
Bcorrelation_id
Cdelivery_tag
Drouting_key
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong property names or missing message acknowledgment.