Spring 集成@MessagingGateway 单个请求的多个回复

Spring Integration @MessagingGateway multiple replies for a single request

我正在尝试使用 Spring 集成创建一个能够订阅外部 legacy/non-spring 服务器的应用程序。我同时使用 AbstractServerConnectionFactoryAbstractClientConnectionFactory。问题是,在我发送启用订阅的消息后,对于单个请求,我收到了多个回复(一个订阅确认,然后每 x 分钟收到一条包含订阅数据的消息)。似乎 @Gateway 不适合这种情况,所以我试图通过在 TcpInboudGateway 上设置请求通道和回复通道 TcpOutboundGateway 来以某种方式将回复重定向到 @MessageEndpoint相同。这没有帮助,我无法摆脱 TcpOutboundGateway 无法关联响应 - 没有待处理的回复...。我试图删除 CachingClientConnectionFactory 并使用纯 AbstractClientConnectionFactory,但它也没有帮助。每个请求和单个响应调用都运行良好。此外,我能够将任何数据包发送到我的应用程序,并且它们都得到了很好的处理。

想了很多天来解决这个问题,但我仍然坚持不懈。经过这么长时间,我认为一定是其中的 @MessagingGateway@Gateway 方法无法处理多个回复,也无法将其委托给 @MessageEndpoint 的问题。有没有办法摆脱 @MessagingGateway 并使用能够执行上述操作的东西?也许有一种方法可以使用 @Header 来释放 @Gateway 处理任何回复的方法?在 github 和文档中的 Spring 集成示例中进行了搜索,但未找到这些问题的答案。

网关专为 1 request/1 回复消息而设计。

要在客户端和服务器之间实现任意双向消息传递,您可以使用一对Collaborating Channel Adapters

... You can also use collaborating adapters (server-side or client-side) for totally asynchronous communication (rather than with request-reply semantics). On the server side, message correlation is automatically handled by the adapters, because the inbound adapter adds a header that allows the outbound adapter to determine which connection to use when sending the reply message. ...