2
votes

I want to read a file by name using Spring Integration. I know how to use file-adapter with poller. But in this case I just want to read a file by name and add it to the input channel.

My application is a standalone jar, and will be invoked using command-line arguments. One of the argument will be the file-name. I am using Spring-Boot as well. Just don't know how to initiate the processing by reading this file and adding this to an input-channel. Do I need a custom gateway?

Thanks

1

1 Answers

1
votes

If I understand you correctly you need to use <context:property-placeholder> and config like this:

<file:inbound-channel-adapter
        channel="input"
        directory="${dir}"
        filename-pattern="${pattern}">
    <poller fixed-delay="${fixedDelay}" time-unit="SECONDS"/>
</file:inbound-channel-adapter>

Where all those placeholders should be your program args, like this:

java myMain --dir=/usr/mydir --patter=myfile.name --fixedDelay=1000

UPDATE

However, no: you don't need <context:property-placeholder> - Spring Boot does that for you!

UPDATE 2

Sorry, you requirement is still not clear. Anyway how about this:

<int-event:inbound-channel-adapter channel="processFileChannel"
    event-types="org.springframework.context.event.ContextRefreshedEvent"
    payload-expression="new java.io.File('${filePath}')"/>

Where filePath is again an command line argument. And property placeholder from Spring Boot.

The <int-event:inbound-channel-adapter> is responsible to listen to ApplicationEvent. In this case we react to the ContextRefreshedEvent - a main event when you applicationContext is ready to do something.