首页 文章

使用相同通道的 spring 集成的多个入站通道适配器

提问于
浏览
4

我正在使用Spring集成的入站通道适配器 . 我想在两个不同的目录下进行轮询 - 每个文件类别 - 并解析位于那里的文件 . 我使用的代码是:

<int:channel id="inputChannel"/>

<file:inbound-channel-adapter id="fileInOne"                        
                              directory="myDirOne"
                              auto-create-directory="true"
                              channel = "inputChannel">
    <int:poller id="one" cron="1/10 * * * * *"/>
</file:inbound-channel-adapter>


<file:inbound-channel-adapter id="fileInTwo"                        
                              directory="myDirTwo"
                              auto-create-directory="true"
                              channel = "inputChannel">
    <int:poller id="two" cron="1/10 * * * * *"/>
</file:inbound-channel-adapter>

两个入站通道适配器都使用相同的通道 . 所以我想知道文件加载的入站通道适配器 .

1 回答

  • 0

    这是我能想到的两种方式:

    一个 . 将每个流通过 Headers 集合,添加一个自定义 Headers ,告诉您从哪个目录开始,然后再输入inputChannel .

    <file:inbound-channel-adapter id="fileInOne"                        
                                  directory="myDirOne"
                                  auto-create-directory="true"
                                  channel = "dirOneEnricher">
        <int:poller id="one" cron="1/10 * * * * *"/>
    </file:inbound-channel-adapter>
    
    <int:header-enricher input-channel="dirOneEnricher" output-channel="inputChannel">
        <int:header name="fileCategory" value="dirOneTypeCategory"/> 
    </int:header-enricher>
    

    ..

    湾由于有效负载是 java.io.File ,您可以使用API来查找此文件所属的目录并执行某些操作 .

相关问题