3

WatchServiceDirectoryScanner/RecursiveLeafOnlyDirectoryScannerファイルシステムでファイルを処理するために使用しています。ファイル イベントが生成され、定義されたエンドポイントでメッセージが受信されますが、そのディレクトリ内のすべてのファイルを処理できない場合があります。

たとえば、15 個のファイルがある場合、10 個のファイルを処理する場合もあれば、5 個のファイルを処理する場合もあります。metastore には、15 個のファイルすべてに関する情報が含まれています"metadata-store.properties"

spring-integration-configuration.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:int="http://www.springframework.org/schema/integration"
        xmlns:int-file="http://www.springframework.org/schema/integration/file"
        xmlns:int-mail="http://www.springframework.org/schema/integration/mail"
        xmlns:int-stream="http://www.springframework.org/schema/integration/stream"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail.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
            http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

        <int:annotation-config />
            <int:channel id="cfpFileIn"></int:channel>
    <int-file:inbound-channel-adapter id="cfpFileIn"
            directory="${cfp.flight.data.dir}" auto-startup="true" scanner="csvDirScanner">
            <int:poller fixed-delay="${cfp.flight.data.dir.polling.delay}"></int:poller>
        </int-file:inbound-channel-adapter>
    <bean id="csvDirScanner"
            class="org.springframework.integration.file.WatchServiceDirectoryScanner">
            <constructor-arg index="0" value="${cfp.flight.data.dir}" />
            <property name="filter" ref="csvCompositeFilter" />
            <property name="autoStartup" value="true" />
        </bean>

    <bean id="csvCompositeFilter"
            class="org.springframework.integration.file.filters.CompositeFileListFilter">
            <constructor-arg>
                <list>
                    <bean
                        class="org.springframework.integration.file.filters.SimplePatternFileListFilter">
                        <constructor-arg value="*.csv" />
                    </bean>
                    <ref bean="persistentFilter" />
                </list>
            </constructor-arg>
        </bean>

    <bean id="persistentFilter"
            class="org.springframework.integration.file.filters.FileSystemPersistentAcceptOnceFileListFilter">
            <constructor-arg index="0" ref="metadataStore" />
            <constructor-arg index="1" name="prefix" value="" />
            <property name="flushOnUpdate" value="true" />
        </bean>

    <bean name="metadataStore"
            class="org.springframework.integration.metadata.PropertiesPersistingMetadataStore">
            <property name="baseDirectory" value="${metadata.dir}"></property>
        </bean>
</beans>

BatchJobScheduler:

import java.io.File;
import java.util.concurrent.locks.ReentrantLock;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.JobParametersInvalidException;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.stereotype.Component;
@Component
public class BatchJobScheduler  {

    private static final Logger logger = LoggerFactory.getLogger(BatchJobScheduler.class);
    @Autowired
protected JobLauncher jobLauncher;

    @Autowired
    @Qualifier(value = "job")
    private Job job;

    @ServiceActivator(inputChannel = "cfpFileIn")
    public void run(File file) {
        String fileName = file.getAbsolutePath();
        logger.info("BatchJobScheduler Running #################"+fileName);
        JobParameters jobParameters = new JobParametersBuilder().addString(
                "input.file", fileName).toJobParameters();


        try {

            JobExecution execution = jobLauncher.run(job,
                    jobParameters);
            logger.info(" BatchJobScheduler Exit Status : " + execution.getStatus() +"::"+execution.getAllFailureExceptions());

        } catch (JobExecutionAlreadyRunningException | JobRestartException
                | JobInstanceAlreadyCompleteException
                | JobParametersInvalidException e) {
            logger.error(" BatchJobScheduler Exit Status : Exception ::",e);
        }
    }
}

構成またはコードが不足しているようです。

提案に基づく:

完全なspring-integration.xmlログ ファイルを git リポジトリに配置しました - https://github.com/chandaku/spring-integration-issue

ここでは 5 つのチャネルが作成され、同時に動作しています。一度に 1 つのチャネルのみを実行すると、ディレクトリ内のすべてのファイルが正常に処理されると思いますが、すべてのファイル チャネルを開くと問題が発生します。

4

0 に答える 0