0
0
RabbitMQdevops~10 mins

Implementing RPC client and server in RabbitMQ - Interactive Code Practice

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' on the server side.

RabbitMQ
channel.queue_declare(queue=[1])
Drag options to blanks, or click blank then click option'
A'rpc_queue'
B'task_queue'
C'jobs_queue'
D'hello'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different queue name than 'rpc_queue' causes client-server mismatch.
2fill in blank
medium

Complete 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'
A'rpc_response'
B'response_queue'
C'amq.rabbitmq.reply-to'
D'callback_queue'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a custom queue name without setting up a consumer on it.
3fill in blank
hard

Fix 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'
Abasic_ack
Bbasic_nack
Cbasic_reject
Dbasic_cancel
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to acknowledge causes message re-delivery and duplicate processing.
4fill in blank
hard

Fill 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'
A'amq.rabbitmq.reply-to'
Bon_response
C'rpc_queue'
Don_request
Attempts:
3 left
💡 Hint
Common Mistakes
Consuming from the wrong queue or using the wrong callback function.
5fill in blank
hard

Fill 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'
A.decode()
B==
Ccorrelation_id
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators or forgetting to decode message bodies.