- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当给定的评估返回 false 时,我需要将消息从我的父流路由到一个新的流,但当该评估返回 true 时让它在父流中继续。目前,我已经能够使用 Spring Integration DSL .filter()
成功实现此功能。方法没有任何问题。但是,我感觉好像在使用 .filter()
这种方式不属于这种方法的真正意图。是否有某种类型的路由器可以用来更好地满足同样的需求?有没有必要改从这个.filter()
实现到基于路由器的实现?
以下面的集成流程配置为例......
@Bean
public IntegrationFlow flow() {
return IntegrationFlows
.from("inboundChannel")
.filter(someService::someTrueFalseMethod, onFalseReturn -> onFalseReturn.discardChannel("otherFlowInboundChannel"))
.handle(someService::someHandleMethod)
.get();
}
@Bean
public IntegrationFlow otherFlow() {
return IntegrationFlows
.from("otherFlowInboundChannel")
.handle(someOtherService::someOtherHandleMethod)
.get();
}
.routeToRecipents()
可能是我需要使用的。在我的场景中,我需要评估消息的 header ,这就是
recipientMessageSelector
的原因。正在使用。
@Bean
public IntegrationFlow flow() {
return IntegrationFlows
.from("inboundChannel"
.routeToRecipients(router -> router
.recipientMessageSelector("otherFlowInboundChannel", someService::someTrueFalseMethod)
.defaultOutputToParentFlow()
)
.handle(someService::someHandleMethod)
.get();
}
@Bean
public IntegrationFlow otherFlow() {
return IntegrationFlows
.from("otherFlowInboundChannel")
.handle(someOtherService::someOtherHandleMethod)
.get();
}
routeToRecipients
似乎有效的解决方案,它与上面的过滤器实现之间真的有什么好处吗?
最佳答案
嗯,这真的不是关于 Java DSL 方法以及如何使用它们。它实际上是关于那些 IE 模式的理论。
我们比较一下Filter
和 RecipientListRouter
来自 EIP!
过滤器 - https://www.enterpriseintegrationpatterns.com/patterns/messaging/Filter.html :
If the message content matches the criteria specified by the Message Filter, the message is routed to the output channel. If the message content does not match the criteria, the message is discarded.
filter
自
false
起与您的期望不符决议你有点丢弃消息。然而,对于那些被丢弃的消息的可能处理,Spring Integration 提供了
discardChannel
启动丢弃子流的选项。所以,我们可以把它当作
if..else
build ...
Then use a Recipient List to inspect an incoming message, determine the list of desired recipients, and forward the message to all channels associated with the recipients in the list.
filter
的问题行为,因为您不会有两个以上具有互斥目的的 channel 。
filter
方法感觉像是滥用流控制(让我想起 Java 中的类似逻辑依赖于流控制的异常处理),它并没有要求我们始终保持规范的行为以在消息不适合时以错误告终健康)状况。
recipientList
is for more complicated scenarios when a selector is used for any arbitrary evaluation, not just plain boolean and has an ability to distribute the same message into several output channels.所以,我不推荐这个简单的
true/false
设想。
Use a Content-Based Router to route each message to the correct recipient based on message content.
true/false
并且它不会滥用流量控制的错误(丢弃),也不会规定我们的收件人列表。而这个也有那个
defaultOutputToParentFlow()
当您想依赖非映射结果时。
filter()
- 与其
true/false
逻辑和
discardChannel
它真的看起来像是基于内容的路由器的特定实现:-)。
关于Spring 集成 DSL 过滤器与 RouteToRecipients 与单个 Recipient 和 DefaultOutputToParentFlow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60231650/
我是使用 Java Config 进行 Spring 集成的初学者,我正在使用以下代码: @EnableIntegration @Configuration @EnableAutoConfigurat
当给定的评估返回 false 时,我需要将消息从我的父流路由到一个新的流,但当该评估返回 true 时让它在父流中继续。目前,我已经能够使用 Spring Integration DSL .filte
我是一名优秀的程序员,十分优秀!