Spring Integration File Supportチュートリアルでは、特定の場所からファイルをポーリングしてさらに処理するチュートリアルを作成しました。私は以下のように同じのための私のbean.xmlを持っているので、ポーリング目的のために、私は春の統合のインバウンドとアウトバウンドチャネルアダプタを使用していますSFTPインバウンド/アウトバウンドチャネルアダプタ用の個別のチャネル宣言がある理由と、単純ファイルインバウンド/アウトバウンドチャネルアダプタ用の理由がない理由は何ですか?
<?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>
今、私の主なクラスがある:
@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("===================================================");
}
}
ファイルを処理するためのHandlerクラスがありますが、これはうまく動作しています。
ここで問題は、SFTPリモートサーバーと同じメカニズムを作り、その場所からファイルをポーリングし、処理されたファイルを別のフォルダ内の同じSFTP場所に置くことです。
私はbean.xmlをそれに応じて設定し、SFTP用のインバウンドとアウトバウンドのチャネルアダプタを作成しました。私がサービスアクチベータの部分に着いたとき、私はインバウンドとアウトバウンドの両方のチャネルアダプタ用に別々のチャネルを設定し、そのIDをservice-activatorに渡す必要があることを発見しました。なぜ、インバウンドとアウトバウンドの両方のチャネルアダプタに個別のチャネルが必要なのですか?また、必要な場合は、スケジュールされたファイルのポーリングサービスにどのように実装するのですか?
私はちょうどSFTPのための同様の設定で模擬テストケースを走らせました、そして、私の陰的なチャンネルについて異論はありません。だから、おそらくあなたの新しい設定に何か間違っている。 –