spring-integration - Spring Integration - 重放相同的流程
问题描述
我有一个像
@Bean
public IntegrationFlow processRequest() {
return flow -> flow.channel(REQUEST_INPUT)
.transform(...)
.enrichHeaders(h -> h.<Storage>headerFunction(...)))
.enrich(this::...)
//.route(ifReplayIsNeeded(), routeToSameFlow())
.enrich(this::...)
.route(..., ...)
.route(..., ...)
.enrich(this::...)
.handle(...)
//.route(ifReplayWasNeeded(), routeBack())
.route(..., ...)
.enrich(this::...)
.transform(...)
.channel(REQUEST_OUTPUT);
}
因此,当满足条件时(请参阅 参考资料ifReplayIsNeeded()
)processRequest()
,必须再次调用流程。然而,不是必须执行整个流程,而是几乎在最后(-> ifReplayWasNeeded()
)这个内部流程必须回到它被调用的地方并完全处理原始流程。
routeToSameFlow()
外观(用于Storage
存储请求/响应和流中使用的其他数据)
Consumer<RouterSpec<Boolean, MethodInvokingRouter>> routeToSameFlow() {
return rs -> rs.resolutionRequired(false)
.subFlowMapping(true, sf -> sf
// 1. storing the current Storage
.enrichHeaders(h -> h.<Storage>headerFunction("store", s -> s))
// 2. creating the req for the internal flow
.transform(internalRequestMapper, "mapFrom")
// 3. routing to the beginning of the flow
.route(Message.class, (m) -> REQUEST_INPUT)
// 4. defining the channel where the internal flow will return to
.channel("RETURN_CHANNEL")
)
.defaultOutputToParentFlow();
}
和routeBack()
Consumer<RouterSpec<Boolean, MethodInvokingRouter>> routeBack() {
return rs -> rs.resolutionRequired(false)
.subFlowMapping(true, sf ->
sf.route(Message.class, (m) -> "RETURN_CHANNEL")
)
.defaultOutputToParentFlow();
}
当我收到以下错误时,我肯定错过了一些概念:
原因:org.springframework.beans.factory.BeanCreationException:“currentComponent”(org.springframework.integration.router.MethodInvokingRouter@60a0f09f)是单向“MessageHandler”,不适合配置“outputChannel”。这是集成流程的结束。
你能帮我如何实现这样的逻辑吗?我应该将主要流程拆分为较小的 IntegrationFlow 吗?
我想尽可能少地干扰主流,这就是为什么我只想在开头添加一条导流路线,在结尾添加一条返回路线。有可能这样做吗?
谢谢!
问候,
V。
解决方案
您可能使所有这些路由器的逻辑过于复杂。考虑在您的主要流程中间只使用简单channel()
的定义,并作为您想要返回的子流程的输出。Java DSL 没有任何限制,只是channel()
在开头和结尾都有定义:您可以自由添加channel()
流定义的任何点。例如:
.handle(...)
.channel("middleOfTheFlow")
.route(ifReplayWasNeeded(), routeBack())
然后你的routeBack()
流定义可能就.channel("middleOfTheFlow")
在最后,在这里处理后的消息将被传递到middleOfTheFlow
主流的通道。
换句话说,anIntegrationFlow
只是将某些业务功能的端点保持在同一位置的逻辑组件,但这并不意味着流中的所有端点都非常严格地相互关联。您始终可以在两者之间有一个通道,并从其他地方向该通道发送消息,订阅该通道的端点将处理该消息。
在文档中查看更多信息:https ://docs.spring.io/spring-integration/docs/current/reference/html/dsl.html#java-dsl
推荐阅读
- css - css input[type=radio] 在 IE 11 上无法正常工作
- bash - 从 bash 脚本作为此处文档运行时未执行 Snowsql 脚本
- python - 使用python在文件中写入avro记录
- wordpress - Facebook 正在加载开放图形图像但未显示
- php - 如何在 api laravel 8 中跟踪文件的上传大小
- node.js - 使用 select 选择多个字段
- grep - 从文本文件中获取与另一个文件中的索引相对应的行?
- python-3.x - 无法在 colab 中安装 fitne
- node.js - 我正在尝试将图像存储在上传文件夹中。但它仍然给出同样的错误
- c# - 统一按下按钮时启用脚本