File Poller активируется либо когда очередь заполнена, либо через заданный промежуток времени

Нас попросили проиндексировать файлы отчетов из папки. Нам нужно индексировать пакетами, то есть мы не будем индексировать, если у нас недостаточно файлов. Тем не менее, мы в конечном итоге будем индексировать, даже если по прошествии определенного времени у нас не будет достаточно файлов. Итак, у нас есть два условия, которые запускают одну и ту же функцию.

Мы смогли правильно настроить очередь, входящий опросник (для получения файлов) и исходящий опросник (для индексации файлов по прошествии x времени). Однако мы все еще не смогли вызвать функцию, когда очередь заполнена. И, хотя я признаю, что мы далеко не эксперты в Spring Integration, поверьте мне, когда я говорю, что мы неоднократно просматривали документацию и видели бесконечные примеры проектов. Но это все еще ускользает от нашей досягаемости.

Достаточно слов. Здесь есть код:

IP-клиент-отчеты-конфигурация:

<?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-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 id="customerReportsFileManager" class="xxx.xxx.xxx.xxx.reports.CustomerReportsFileManager" />

    <int:channel id="customerReportInputChannel" />

    <int-file:inbound-channel-adapter channel="customerReportInputChannel" directory="${customer.reports.directory}">
        <int:poller time-unit="SECONDS" fixed-delay="3" />
    </int-file:inbound-channel-adapter>

    <int:service-activator input-channel="customerReportInputChannel" output-channel="customerReportIndexationInputChannel"
                           ref="customerReportsFileManager" method="prepareFile" />

    <int:channel id="customerReportIndexationInputChannel">
        <int:queue capacity="3" /> <!-- Capacity -1 -->
    </int:channel>

    <int:outbound-channel-adapter channel="customerReportIndexationInputChannel" ref="customerReportsFileManager" method="indexReports">
        <int:poller time-unit="SECONDS" fixed-delay="60" />
    </int:outbound-channel-adapter>

</beans>

CustomerReportsFileManager:

public class CustomerReportsFileManager {
    private static final Logger LOGGER = LoggerFactory.getLogger(CustomerReportsFileManager.class);

    public File prepareFile(File file) {
        LOGGER.warn("[prepareFile] " + file.getPath());

        return file;
    }

    public void indexReports(File file) {
        LOGGER.warn("[indexReports] " + file.getPath());
    }
}

1 ответ

Решение

Вы используете неправильный подход.

Не используйте для этого очередь - просто напишите FileListFilter и вставить его в файловый адаптер - фильтр может возвращать пустой список, пока не пройдет требуемое время или не будет достигнуто требуемое количество файлов.

Другие вопросы по тегам