I have developed a code going through Spring Integration File Support tutorial, in which I am polling files from specific location and processing them further. For polling purpose I have used Spring Integration's Inbound and Outbound channel adapters so I have my bean.xml for the same as below:
<?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:integration="http://www.springframework.org/schema/integration"
xmlns:file="http://www.springframework.org/schema/integration/file"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/file
http://www.springframework.org/schema/integration/file/spring-integration-file.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
<file:inbound-channel-adapter id="filesIn"
directory="file:${java.io.tmpdir}/input">
<integration:poller id="poller" fixed-rate="60000" />
</file:inbound-channel-adapter>
<integration:service-activator
input-channel="filesIn" output-channel="filesOut" ref="handler" />
<file:outbound-channel-adapter id="filesOut"
directory="file:${java.io.tmpdir}/archive" delete-source-files="true">
</file:outbound-channel-adapter>
<bean id="handler" class="com.m.c.Handler" />
</beans>
Now my main class is:
@SpringBootConfiguration
@EnableScheduling
public class App{
private static final Log LOGGER = LogFactory.getLog(App.class);
public static void main( String[] args )
{
SpringApplication.run(App.class, args);
}
@Scheduled(fixedDelay = 60000)
public static void display() throws InvalidFormatException, IOException{
ApplicationContext context = new ClassPathXmlApplicationContext("/spring/integration/bean.xml", App.class);
File inDir = (File) new DirectFieldAccessor(context.getBean(FileReadingMessageSource.class)).getPropertyValue("directory");
LiteralExpression expression = (LiteralExpression) new DirectFieldAccessor(context.getBean(FileWritingMessageHandler.class)).getPropertyValue("destinationDirectoryExpression");
File outDir = new File(expression.getValue());
LOGGER.info("Input directory is: " + inDir.getAbsolutePath());
LOGGER.info("Archive directory is: " + outDir.getAbsolutePath());
LOGGER.info("===================================================");
}
}
and there is a Handler class for processing the files, this is working fine for me.
Now the question is I want to make the same mechanism for SFTP remote server and poll the file from that location and put the processed files on the same SFTP location in different folder.
So I configured my bean.xml accordingly and wrote inbound and outbound channel adapters for SFTP. When I came to the service-activator part I found that I need to configure separate channels for Inbound and Outbound channel adapters and give their id's in service-activator which I didn't see in simple file poller which is working fine. So why separate channels are needed for inbound and outbound channel adapters? And if they are required how do we implement the same for a Scheduled file polling service?