希望这是我要问的关于 spring 集成的最后一个问题。
面临以下问题:在相当长的 IntegrationFlow dsl 表的末尾有一段代码:
return IntegrationFlows.
//...
.enrichHeaders(headerEnricherSpec -> headerEnricherSpec.header("jms_replyTo", responseQueue(), true)) // IntegrationMessageHeaderAccessor.CORRELATION_ID is not acceptable though message came from outgoingGateway of another application with this header been set
.handle(requestRepository::save)
.handle(
Jms.outboundAdapter(queueConnectionFactory()).destination(serverQueue())
)
.get();
问题是在像 requestRepository::save
这样的代码之后,处理链被破坏了。这个技巧只有在有一个网关作为处理程序参数传入时才有效。
如何克服这个限制?我认为在这里使用 wireTap 不会达成协议(protocol),因为它是异步的。在这里,实际上,我保存消息以存储它的 jms_replyTo
header ,并在相应的回复从服务器返回后用保存的消息替换它(智能代理企业集成模式)。
有什么建议吗?
最佳答案
不知道你为什么说“最后一个问题”。你打算放弃 Spring Integration 吗? :-(
我猜你的问题是下一个 .handle()
因为你的 requestRepository::save
是单向的 MessageHandler
(void
从 save()
方法返回)。或者您的 save()
返回 null
。
IntegrationFlow
是一个执行链,下一个执行将在前一个执行后以其非空结果调用。
所以,请分享您的requestRepository::save
!
更新
Neither did help declaring MessageHandler bean as a (m) -> requestRepository.save(m) and passing it into handle(..) method as a param.
是的...我想看看您的requestRepository::save
的签名。
所以,看。使用 .handle()
的方法引用,您应该确定您的场景。如果您单向
处理流停止,则足以遵循org.springframework.messaging.MessageHandler
契约。你的方法签名应该是这样的:
public void myHandle(Message<?> message)
如果您想继续流程,您应该从服务方法中返回任何内容。该结果成为下一个 .handle()
的 payload
。
在这种情况下,您的方法应遵循 org.springframework.integration.dsl.support.GenericHandler
协定。您的方法签名可能如下所示:
public Bar myHandle(Foo foo, Map<String, Object> headers)
.handle()
的方法引用就是这样工作的。
您应该了解此方法链
样式的工作原理。前一个方法的输出是下一个方法的输入。在我们的例子中,我们保护流免受死代码的影响,例如返回 void
的 MessageHandler
,但还有下一个流成员。这就是您看到 This is the end of the integration flow.
错误的原因。
关于java - Spring集成流程: perform task within flow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35320979/