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

pba*_*bal 5 integration spring

我正在使用 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>
Run Code Online (Sandbox Code Playgroud)

两个入站通道适配器使用相同的通道。所以我想知道文件是从哪个入站通道适配器加载的。

Bij*_*men 0

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

A。通过标头丰富器传递每个流,添加一个自定义标头,告诉您从哪个目录开始,然后传递到 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>
Run Code Online (Sandbox Code Playgroud)

..

b. 由于有效负载是java.io.File,您可以使用 API 来找出该文件属于哪个目录并采取一些操作。