Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a queue named 'rpc_queue' on the server side.
RabbitMQ
channel.queue_declare(queue=[1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different queue name than 'rpc_queue' causes client-server mismatch.
✗ Incorrect
The server must declare the queue named 'rpc_queue' to receive RPC requests.
2fill in blank
mediumComplete the code to publish a message with a reply_to property set for RPC response.
RabbitMQ
channel.basic_publish(exchange='', routing_key='rpc_queue', properties=pika.BasicProperties(reply_to=[1]), body='5')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a custom queue name without setting up a consumer on it.
✗ Incorrect
The special queue 'amq.rabbitmq.reply-to' is used for direct reply-to in RabbitMQ RPC clients.
3fill in blank
hardFix the error in the server callback function to acknowledge the message after processing.
RabbitMQ
def on_request(ch, method, props, body): response = fib(int(body)) ch.basic_publish(exchange='', routing_key=props.reply_to, properties=pika.BasicProperties(correlation_id=props.correlation_id), body=str(response)) ch.[1](delivery_tag=method.delivery_tag)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to acknowledge causes message re-delivery and duplicate processing.
✗ Incorrect
The server must acknowledge the message with basic_ack to tell RabbitMQ it was processed.
4fill in blank
hardFill both blanks to set up a consumer on the client side that listens to the reply queue and matches correlation IDs.
RabbitMQ
channel.basic_consume(queue=[1], on_message_callback=[2], auto_ack=True)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Consuming from the wrong queue or using the wrong callback function.
✗ Incorrect
The client consumes from 'amq.rabbitmq.reply-to' with the on_response callback to handle RPC replies.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that filters messages with matching correlation_id and extracts their bodies.
RabbitMQ
responses = {k: v[1] for k, v in messages.items() if k [2] props.[3] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators or forgetting to decode message bodies.
✗ Incorrect
We decode the message body, filter keys equal to the correlation_id property to get matching responses.