Reputation: 496
I am newbie to spring integration.So please pardon me if I am asking something ordinary. I do have a one simple use case. I have configured ftp inbound channel adaptor as below. Using it I am able to pull remote check files in local directory. i.e.D:/Outbound. Now I want to poll local directory i.e. i.e.D:/Outbound to add further business logic. i.e. Download a original file from remote based on check file status and move relevant check files to other directory location. How should I do it ? Any sample quick code or reference guide/links would be appreciated.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd">
<context:property-placeholder location="/ftp/ftp.properties"/>
<context:component-scan base-package="com.sandbox.ftp"/>
<!-- FTP inbound channel adapter for reading the input check files -->
<int-ftp:inbound-channel-adapter id="ftpInbound"
channel="ftpInboudChannel"
session-factory="ftpClientFactory"
auto-create-local-directory="true"
local-directory="D:/outBound"
remote-directory="."
filename-regex=".*\.chk$">
<int:poller fixed-rate="5000" />
</int-ftp:inbound-channel-adapter>
<int:channel id="ftpInboudChannel"/>
<!--Service Activator which will intiates the download of original source file -->
<int:service-activator input-channel="ftpInboudChannel" ref="myPojo" method="processFile" />
<bean id="myPojo" class="com.sandbox.ftp.CheckFileProcessor" />
<!-- FTP inbound channel adapter for downloading the original remote files -->
<int-ftp:inbound-channel-adapter id="ftpInboundDownload"
channel="ftpInboudDownloadChannel"
session-factory="ftpClientFactory"
auto-create-local-directory="true"
local-directory="D:/outBound/original"
remote-directory="."
filename-regex=".*\.txt$">
<int:poller fixed-rate="5000"/>
</int-ftp:inbound-channel-adapter>
<int:channel id="ftpInboudDownloadChannel"/>
</beans>
Now based on Gary's comment,I have used the service activator and able to download the original source files.i.e. *.txt. Now i want to move the associated check files to the same folder once the original source file is downloaded. i.e. *.chk to D:/outBound/original. Any thoughts ?
Upvotes: 3
Views: 771
Reputation: 174574
All that does is dump the file into the queue channel - I assume you got that from the sample app.
See the spring integration reference.
A simple app might do this (remove the <queue/>
from the channel)...
<int:channel id="ftpInboudChannel"/>
<int:service-activator input-channel="ftpInboudChannel"
ref="myPojo" method="processFile" />
<bean id="myPojo" class="foo.MyPojo" />
public class MyPojo {
public void processFile(File fileToProcess) {
...
}
}
EDIT
I am not sure entirely what your use case is, but it sounds like you only want to fetch the .txt
file when the .chk
file is present.
An inbound channel adapter is not really appropriate for that - all it does is synchronize the local directory to the remote directory, it sounds like you need something like this, using the GET command with an outbound channel adapter...
<int:channel id="ftpInboudChannel"/>
<int:transformer input-channel="ftpInboudChannel" output-channel="ftpGet"
expression="payload.name.replace('chk$', 'txt')" />
<int:ftp-outbound-gateway request-channel="ftpGet" command="get"
...
replyChannel="ftpGot" />
<int:service-activator input-channel="ftpGot" ... />
In other words, fetch the file on-demand rather than polling for it.
You could also use the gateway to list (LS) the files and fetch those you are interested in.
Upvotes: 1