Spring Integration DSL 中的路由

异想天开

我正在使用以下 IntegrationFlow 表单,其中我通过标题值过滤我的主题消息:

IntegrationFlows.from ( 
                        Jms.messageDrivenChannelAdapter (  Jms.container(factory, connection)
                                                              .messageSelector("X-HEADER = 'X_VALUE'")
                                                              .get() 
                                                        )
                           .get()
                      )
                .handle(XMessageHandler)
                .get();

..或者

IntegrationFlows.from ( 
                        Jms.messageDrivenChannelAdapter (  Jms.container(factory, connection)
                                                              .get() 
                                                        )
                           .get()
                      )
                .filter(Message.class, filterByHeaderPropertySelector(X_HEADER, X_VALUE)
                .handle(XMessageHandler)
                .get();

但是现在,一种新型的预期流加入了主题,因此鉴别器标头具有新值 Y。因此filter(Message.class, filterByHeaderPropertySelector(Y_HEADER, Y_VALUE),目标为的新过滤器YMessageHandler

我的问题是如何以最小的影响重用基础设施。将过滤器与路由一起使用是理想的,但route操作似乎并没有以相同的方式内联。也许有更简单/明显的方法?

另外,我应该为每个消息选择器复制适配器吗?将消息选择器放在容器设置中或将其作为集成流程的一部分有什么区别。是否有任何性能下降或集成构建器是否巧妙地对其进行了优化?我的意思是,很可能将选择器放在流上并不能避免解析消息等,而在容器的定义中,它只是从一开始就过滤它。解决这个问题的最佳方法是什么?

阿尔乔姆·比兰

当然,最好的解决方案是容器上的选择器。这样消息过滤是在 Broker 上完成的。

无论如何,您必须查看Router附加信息并查阅当前值的标头以选择正确的下行通道。

过滤器是一种二进制路由器,但任何方式都可以更好地使用路由器实现逻辑:https : //github.com/spring-projects/spring-integration-java-dsl/wiki/Spring-Integration-Java-DSL -参考#routers

更新

子流映射示例:

.<Integer, Boolean>route(p -> p % 2 == 0, m -> m
        .subFlowMapping(true, sf -> sf.<Integer>handle((p, h) -> p * 2))
        .subFlowMapping(false, sf -> sf.<Integer>handle((p, h) -> p * 3)))

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Spring Integration JMS DSL

Spring Integration 中的动态路由

Spring Integration DSL FTP问题

Spring Integration Java DSL错误

Spring Integration DSL通道支持

Spring Integration DSL KafkaProducerContext配置

AcceptOnceFileListFilter 在 Spring Integration JAVA DSL 中覆盖 SimplePatternFileListFilter

在Spring Integration DSL服务激活器中丢弃消息

Spring Integration DSL流变量以在流中存储和检索

如何使用Spring Integration DSL从JMS队列中解组XML

Spring Integration DSL-等待流中通道的输入

Spring Integration Java DSL-流中的可重用对象

如何在Spring Integration(DSL)中公开“ Content-Disposition”?

Spring Integration 4-在Java DSL中配置LoadBalancingStrategy

Spring Integration - Java DSL 中的服务激活器

Spring Integration Java DSL:如何使用channelMapping方法路由到标题中包含标题的通道?

Spring Integration Java DSL:如果发生错误,如何将流路由到错误通道

Spring Integration DSL添加中间流程事务

Spring Integration DSL - 与网关块线程的组合

用于删除的SFTP的Spring Integration DSL删除

Spring Integration DSL SFTP良好实践

Spring Integration DSL缓冲器

捕获Spring Integration DSL错误配置异常?

使用Spring Integration DSL逐行读取文件

Spring Integration DSL JMS请求/答复流

Spring Integration DSL:HTTP出站网关

Kafka 0.9 Spring Integration DSL配置

Spring Integration DSL ScatterGather流模块

如何在Spring Integration Java DSL中创建标头值路由器并为其分配默认输出通道?