gpt4 book ai didi

java - JMS - CorrelationID 与 ReplyTo

转载 作者:行者123 更新时间:2023-12-02 09:48:47 25 4
gpt4 key购买 nike

我正在使用 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.

因此它明确建议使用 CorrelationID 作为请求/回复模式。

我还发现 JmsTemplatesendAndReceive 方法,旨在实现类似的目标。 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。如果您使用不同的请求/回复队列,那么您需要一些东西来将回复与其请求相关联;因此correlationId。

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

关于java - JMS - CorrelationID 与 ReplyTo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56473137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com