Multiple inbound spring integration adapter channel using the same channel

I am using spring inbound-channel adapter integration. I want to poll in two different directories - one category of files - and analyze the files that are there. The code I'm using is:

<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> 

Both inbound channel adapters use the same channel. Therefore, I want to know from which adapter of the incoming channel the file was downloaded.

+4
source share
1 answer

These are two ways I can think of:

a. Pass each stream through the header, add a custom header that tells you which directory you started from, and then with the input channel.

 <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> 

..

b. Since the payload is java.io.File , you can use the API to find out which directory this file belongs to and take some action.

0
source

All Articles