Complete the code to set a timeout for the RPC call.
channel.basic_publish(exchange='', routing_key='rpc_queue', properties=pika.BasicProperties(reply_to=callback_queue, correlation_id=corr_id), body=request_body) channel.connection.process_data_events(time_limit=[1])
The process_data_events method with time_limit=10 sets a 10-second timeout for waiting for the RPC response.
Complete the code to raise an exception if the RPC response is not received in time.
if response is None: raise [1]('RPC call timed out')
TimeoutError is the appropriate exception to indicate a timeout occurred.
Fix the error in the code to correctly check the correlation ID in the RPC response.
if props.correlation_id != [1]: return
The variable corr_id holds the correlation ID to match the response.
Fill both blanks to set up the callback queue and consume messages with a timeout.
result = channel.queue_declare(queue='', exclusive=True) callback_queue = result.[1] channel.basic_consume(queue=callback_queue, on_message_callback=[2], auto_ack=True)
queue_declare returns an object with the queue name in method.queue. The callback function is passed as callback.
Fill all three blanks to create a dictionary comprehension that filters responses received within the timeout.
responses = {corr_id: body for corr_id, body in messages.items() if body is not None and corr_id [1] [2]The comprehension checks if corr_id is in valid_ids and combines conditions with and.