Complete the code to send a message to the queue named 'task_queue'.
channel.basic_publish(exchange='', routing_key='[1]', body='Hello World!')
The routing_key specifies the queue name. Here, 'task_queue' is the correct queue to send the message.
Complete the code to declare a queue for RPC server to listen on.
channel.queue_declare(queue='[1]')
The RPC server listens on 'rpc_queue' to receive requests.
Fix the error in the code to send an RPC request with a unique correlation id.
channel.basic_publish(exchange='', routing_key='rpc_queue', properties=pika.BasicProperties(correlation_id=[1]), body='Request')
The correlation_id must be a string. Using quotes around the id is required.
Fill both blanks to create a dictionary comprehension that filters messages with a correlation id matching the request.
responses = {k: v for k, v in messages.items() if k [1] request_id and v [2] 'done'}The comprehension selects items where the key equals the request_id and the value does not equal 'done'.
Fill all three blanks to create a dictionary comprehension that maps request IDs to their responses if the response status is 'success'.
result = [1]: [2] for [3] in responses.items() if v == 'success'
The comprehension maps each request ID (req_id) to its response (v) from the items (req_id, v) where the response status is 'success'.