【问题标题】:Spring Integration - Move File After Xpath-splitterSpring Integration - 在 Xpath-splitter 之后移动文件
【发布时间】:2015-12-03 19:43:15
【问题描述】:

我正在使用 spring 集成,我有下一个案例:我正在读取一个带有 int-file:inbound-channel-adapter 的 XML 文件,然后我用 int-xml:xpath-splitter,问题是我需要在分割后移动文件。

我想要 int-xml:xpath-splitter 的所有功能以及移动文件,我应该实现扩展 XPathMessageSplitter 的自定义拆分器吗?或者有没有其他方法可以使用开箱即用的组件来做到这一点?

谢谢。

<int-xml:xpath-splitter id="salesTransSplitter" 
                   input-channel="salesInputChannel"
                   output-channel="splitterOutChannel" order="1">
    <int-xml:xpath-expression expression="/sales_transactions/trans"/>      
</int-xml:xpath-splitter>   

【问题讨论】:

    标签: spring spring-integration splitter


    【解决方案1】:

    这样的东西应该可以工作......

    <int-file:inbound ... channel="foo" />
    
    <int:publish-subscribe-channel id="foo" />
    
    <int-xml:xpath-splitter input-channel="foo" ... order="1" />
    
    <int-service-activator input-channel="foo" order="2"
          expression="payload.renameTo(new java.io.File('/newDir/' + payload.name)" output-channel="nullChannel" />
    

    如果您想测试重命名是否成功,请发送到 nullChannel 以外的其他频道 - boolean true 表示成功。

    编辑

    对此感到抱歉; order 应该在每个消费端点上都支持,我将打开一个 JIRA 问题。

    order 不是绝对必要的;如果不存在order,将使用它们在配置中出现的顺序;我只是更喜欢让它明确。

    有(至少)两种解决方法:

    1. BOTH 消费者中删除 order 属性,它们将按照它们在 XML 中出现的顺序被调用。
    2. 将 XPath 拆分器配置为普通拆分器,确实支持顺序...

      <int:splitter id="salesTransSplitter" order="1"
                 input-channel="salesInputChannel"
                 output-channel="splitterOutChannel" order="1">
          <bean class="org.springframework.integration.xml.splitter.XPathMessageSplitter">
              <constructor-arg value="/sales_transactions/trans" />
          </bean>
      </int-xml:xpath-splitter>   
      

    【讨论】:

    • 谢谢 Gary,但我从 Splitter 得到了这个例外。引起:org.xml.sax.SAXParseException;行号:97;列号:70; cvc-complex-type.3.2.2:没有 está permitido que el atributo 'order' aparezca en el elemento 'int-xml:xpath-splitter'。 xpath-splitter 中不允许使用“order”属性。查看我帖子中的编辑以获取配置示例。顺便说一句,我正在使用 Spring Integration 4.1.6 RELEASE。
    • 很抱歉;这是一个错误JIRA here;请参阅我的编辑以了解一些变通方法。
    猜你喜欢
    • 2018-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-05
    • 2016-04-11
    • 1970-01-01
    相关资源
    最近更新 更多