JMS - CorrelationID 与 ReplyTo

JMS - CorrelationID vs ReplyTo

我正在使用 Spring Framework 中的 JmsTemplate 通过 JMS 进行集成。我想对外部系统执行同步(即阻塞)调用。我读过那个 为此,我应该使用 CorrelationID。 JMS specification 说:

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.

所以它明确建议对 request/reply 模式使用 CorrelationID。

我还发现 JmsTemplate 具有旨在实现类似目标的 sendAndReceive 方法。 sendAndReceive 在内部使用 doSendAndReceive 根据 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.

现在我真的很困惑。 CorrelationID header 与 ReplyTo header 是否有共同点?这两种不同的方式是实现同步调用的吗?或者两者应该一起使用?非常欢迎用通俗易懂的英语进行简单说明。

他们并没有真正的关系。如果您为每个请求使用临时回复队列,则不需要 correlationId。如果您使用不同的 request/reply 队列,那么您需要一些东西来关联对其请求的回复;因此 correlationId.

Spring Integration's outbound gateway 支持这两种方法并为您处理关联(无论使用哪种技术,调用线程都会阻塞直到收到回复)。