Spring Integration,如何更好地描述验证组件

时间:2017-07-06 14:29:35

标签: java spring validation spring-integration

我的流程定义为

return IntegrationFlows.from(
(MessageSourceSpec<?, ? extends MessageSource<?>>) Files.inboundAdapter(directory)
           .autoCreateDirectory(false)
           .patternFilter("*.xml"),
  e -> e.poller(Pollers.fixedDelay(1000)) )) 
  .transform(new TransformXmlToMyDocument())
  .transform(new DataValidator())  // VALIDATOR
  .transform(new TransformMyDocumentToRabbitDomain())
  .channel(pubSubRabbitOutput)
  .get();

问题是验证者。目前我作为&#34;透明&#34;如果消息中的数据无效,则抛出的变换器。整个流程将被包装在伪事务中以处理错误,如#34; how to move processed file to another directory using Spring integration ftp inbound adapter&#34;中所示。

但是在Flow中包含逻辑验证器的最佳方法是什么?它应该是变形剂还是其他种类的流动成分?

1 个答案:

答案 0 :(得分:1)

Filter EIP。当然,Spring Integration在这个问题上提供one

DataValidator必须返回true/false条件,并且您的弃牌逻辑有throw-exception-on-rejection选项:

 .filter(new DataValidator(), "validate", e -> e.throwExceptionOnRejection(true))