Copying multiple files from various sources to various destinations via Spring Integration

237 views Asked by At

I am presented with the following use case.

I am receiving a Message<Foo> object on my input channel, where Foo object has 2 properties

public class Foo {  
    ...
    public String getSourcePathString();
    public String getTargetPathString();
    ...
}

sourcePathString is a String which denotes where the source file is located, while targetPathString is a place where the file should be copied to.

Now, I do know how to use file:outbound-channel-adapter to copy the file to a custom target location via FileNameGenerator, however, I am not sure how I can provide the location where to read the file from in file:inbound-channel-adapter and how to activate the reading when the message is received only.

What I have so far is a custom service activator where I perform copying in my own bean, however, I'd like to try and use Spring Integration for it.

So, is there a way to implement triggerable file copying in Spring Integration with already present components?

1

There are 1 answers

0
Gary Russell On

You cannot currently change the input directory dynamically on the inbound channel adapter.

The upcoming 4.2 release has dynamic pollers which would allow this.

However, it seems the adapter is not really suitable for your use case - it is a polled adapter, whereas you want to fetch the file on demand.

You could minimize your user code by configuring a FileReadingMessageSource, set the directory and call receive() to get the file.