0
0
RabbitMQdevops~10 mins

Correlation ID for matching replies in RabbitMQ - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Correlation ID for matching replies
Send Request with Correlation ID
Message Broker routes request
Consumer processes request
Consumer sends reply with same Correlation ID
Sender receives reply
Match reply to request using Correlation ID
Process reply
This flow shows how a sender tags a request with a unique Correlation ID, which the consumer copies back in the reply. The sender uses this ID to match replies to requests.
Execution Sample
RabbitMQ
channel.basic_publish(exchange='', routing_key='rpc_queue',
  properties=pika.BasicProperties(correlation_id=corr_id, reply_to=callback_queue),
  body=request_body)

# Later, on receiving reply:
if props.correlation_id == corr_id:
  process_reply(body)
Send a request with a Correlation ID and reply_to queue, then match incoming replies by Correlation ID.
Process Table
StepActionCorrelation IDQueueResult
1Send request messageabc123rpc_queueMessage sent with correlation_id=abc123
2Broker routes messageabc123rpc_queueMessage delivered to consumer
3Consumer processes requestabc123rpc_queueRequest processed
4Consumer sends replyabc123callback_queueReply sent with correlation_id=abc123
5Sender receives replyabc123callback_queueReply received
6Match reply to requestabc123callback_queueCorrelation ID matches, reply processed
7Check for other repliesnonecallback_queueNo more replies, stop
💡 No more replies to process, execution ends
Status Tracker
VariableStartAfter Step 1After Step 4After Step 6Final
corr_idnoneabc123abc123abc123abc123
request_sentfalsetruetruetruetrue
reply_receivedfalsefalsetruetruetrue
reply_processedfalsefalsefalsetruetrue
Key Moments - 3 Insights
Why must the reply have the same Correlation ID as the request?
The reply uses the same Correlation ID so the sender can match it to the original request, as shown in step 6 of the execution table.
What happens if the Correlation ID does not match any request?
The sender ignores the reply because it cannot match it to a request, preventing confusion or wrong processing (see step 6).
Why do we need a reply_to queue in the request message?
The reply_to queue tells the consumer where to send the reply, enabling the sender to receive it back (step 4).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the Correlation ID when the consumer sends the reply?
Anone
Babc123
Cxyz789
Dcallback_queue
💡 Hint
Check step 4 in the execution table where the consumer sends the reply.
At which step does the sender confirm the reply matches the request?
AStep 2
BStep 3
CStep 6
DStep 5
💡 Hint
Look for the step where correlation ID matching happens in the execution table.
If the reply_to queue was missing in the request, what would change in the execution?
AThe sender would not receive the reply
BThe consumer would not receive the request
CThe reply would not be sent
DThe Correlation ID would be lost
💡 Hint
Refer to step 4 and 5 about reply sending and receiving.
Concept Snapshot
Use a unique Correlation ID in request messages to track replies.
Include reply_to queue so consumer knows where to send replies.
Consumer copies Correlation ID in reply.
Sender matches replies by Correlation ID to process correctly.
This avoids confusion when multiple requests are in flight.
Full Transcript
This visual execution shows how a sender uses a Correlation ID to track replies in RabbitMQ. The sender sends a request message with a unique Correlation ID and a reply_to queue. The message broker routes the request to the consumer. The consumer processes the request and sends a reply message back to the reply_to queue, copying the same Correlation ID. The sender listens on the reply_to queue and matches incoming replies by their Correlation ID to the original request. This ensures the sender processes the correct reply for each request. The execution table traces each step from sending the request to processing the reply. Variable tracking shows how the Correlation ID and message states change. Key moments clarify why the Correlation ID and reply_to queue are essential. The quiz tests understanding of these steps and their importance.