Complete the code to set a correlation ID when sending a message.
channel.basic_publish(exchange='', routing_key='task_queue', body=message, properties=pika.BasicProperties(correlation_id=[1]))
The correlation ID should be a unique string to match replies. Here, 'abcde-12345' is a valid string ID.
Complete the code to check if the reply message has the expected correlation ID.
if method.properties.correlation_id == [1]: process_reply(body)
We compare the reply's correlation_id to the original string ID to match the response.
Fix the error in the code to correctly set the correlation ID in the reply message properties.
channel.basic_publish(exchange='', routing_key=props.reply_to, body=response, properties=pika.BasicProperties([1]=props.correlation_id))
The correct property name is 'correlation_id' in pika.BasicProperties.
Fill both blanks to create a reply queue and consume messages with a callback.
result = channel.queue_declare(queue='', exclusive=[1]) channel.basic_consume(queue=result.method.queue, on_message_callback=[2], auto_ack=True)
Setting exclusive=True creates a private reply queue. The callback function 'handle_reply' processes incoming messages.
Fill all three blanks to send a message with a correlation ID, set up a reply queue, and start consuming replies.
corr_id = [1] channel.basic_publish(exchange='', routing_key='rpc_queue', body=request, properties=pika.BasicProperties(reply_to=callback_queue, correlation_id=corr_id)) channel.basic_consume(queue=callback_queue, on_message_callback=[2], auto_ack=[3])
We assign a unique string to corr_id, use 'handle_response' as the callback, and set auto_ack to True for automatic message acknowledgment.