Java 为什么SFTP入站/出站通道适配器有单独的通道声明,而简单文件入站/出站通道适配器没有单独的通道声明?
我已经开发了一段代码,通过教程,在其中我从特定位置轮询文件并进一步处理它们。出于轮询目的,我使用了Spring集成的入站和出站通道适配器,因此我使用了bean.xml,如下所示:Java 为什么SFTP入站/出站通道适配器有单独的通道声明,而简单文件入站/出站通道适配器没有单独的通道声明?,java,spring-integration,spring-integration-sftp,Java,Spring Integration,Spring Integration Sftp,我已经开发了一段代码,通过教程,在其中我从特定位置轮询文件并进一步处理它们。出于轮询目的,我使用了Spring集成的入站和出站通道适配器,因此我使用了bean.xml,如下所示: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.
<?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>
还有一个处理程序类用于处理文件,这对我来说很好
现在的问题是,我想为SFTP远程服务器创建相同的机制,从该位置轮询文件,并将处理后的文件放在不同文件夹中的相同SFTP位置
因此,我相应地配置了bean.xml,并为SFTP编写了入站和出站通道适配器。当我谈到ServiceActivator部分时,我发现我需要为入站和出站通道适配器配置单独的通道,并在ServiceActivator中提供它们的id,而我在简单文件轮询器中没有看到,它工作正常。那么,为什么入站和出站通道适配器需要单独的通道呢?如果需要它们,我们如何为定时文件轮询服务实现相同的功能?您没有显示有问题的配置,因此我不确定您的具体要求,但通道适配器上的通道是可选的;如果省略,则频道名称与
id
相同。但总有一个频道。您是否需要实际声明频道取决于消费者方面
如果在出站适配器上显式使用
通道
,则需要声明通道。这在入站适配器上是不必要的,因为service activator将自动声明其输入通道(如果不存在)。我刚刚使用类似的SFTP配置运行了模拟测试用例,对于我的隐式通道没有任何异议。所以,您的新配置可能有问题。
@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("===================================================");
}
}