Reputation: 4341
I'm working on integration via JMS using JmsTemplate
from Spring Framework. I want to execute synchronous (i.e. blocking) call to the external system. I've read that
in order to do this I should use CorrelationID. JMS specification says:
A client can use the JMSCorrelationID header field to link one message with another. A typically use is to link a response message with its request message.
So it clearly suggests using CorrelationID for request/reply pattern.
I've also discovered that JmsTemplate
has sendAndReceive
method that was designed to achieve similar goal. sendAndReceive
uses internally doSendAndReceive
which according to javadoc:
Send a request message to the given Destination and block until a reply has been received on a temporary queue created on-the-fly.
Now I'm really confused. Does CorrelationID header have something in common with ReplyTo header. Are these two different ways to achieve synchronous call? Or maybe both should be used together? Simple clarification in plain English would be more than welcome.
Upvotes: 1
Views: 1719
Reputation: 174604
They are not really related. If you use a temporary reply queue for each request, you don't need a correlationId. If you use distinct request/reply queues then you need something to correlate a reply to its request; hence correlationId.
Spring Integration's outbound gateway supports both methods and handles the correlation for you (the calling thread blocks until the reply is received, regardless of which technique is used).
Upvotes: 1