Spring Integration File Splitter, отправляющий файловые маркеры в качестве полезной нагрузки

У меня есть исходный модуль spring xd, который разбивает текстовый файл построчно. Я хотел увидеть имя файла и подсчитать количество строк в файле, поэтому я использую разделитель файлов с файловыми маркерами. Но проблема в том, что если у меня есть одна запись в файле, файл count поступает как полезная нагрузка, и приходят 3 строки (1 запись + 2 от маркеров файла начинаются и заканчиваются), поэтому мой процессор, который ожидает полезную нагрузку в виде записи файла, получает некоторые файловые маркеры. Как я могу сделать их как заголовки и не отображаться в полезная нагрузка

<?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-aws="http://www.springframework.org/schema/integration/aws"
           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/aws http://www.springframework.org/schema/integration/aws/spring-integration-aws-1.0.xsd">

        <int:poller fixed-delay="${fixed-delay}" default="true"/>

        <bean id="credentials" class="org.springframework.integration.aws.core.BasicAWSCredentials">
            <property name="accessKey" value="${accessKey}"/>
            <property name="secretKey" value="${secretKey}"/>
        </bean>

        <bean
                class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="location">
                <value>dms-aws-s3-nonprod.properties</value>
            </property>
        </bean>

        <bean id="clientConfiguration" class="com.amazonaws.ClientConfiguration">
            <property name="proxyHost" value="${proxyHost}"/>
            <property name="proxyPort" value="${proxyPort}"/>
            <property name="preemptiveBasicProxyAuth" value="false"/>
        </bean>
    <bean id="s3Operations" class="org.springframework.integration.aws.s3.core.CustomC1AmazonS3Operations">
        <constructor-arg index="0" ref="credentials"/>
        <constructor-arg index="1" ref="clientConfiguration"/>
        <property name="awsEndpoint" value="s3.amazonaws.com"/>
        <property name="temporaryDirectory" value="${temporaryDirectory}"/>
        <property name="awsSecurityKey"  value="${awsSecurityKey}"/>
    </bean>



    <!-- aws-endpoint="https://s3.amazonaws.com"  -->
    <int-aws:s3-inbound-channel-adapter aws-endpoint="s3.amazonaws.com"
                                        bucket="${bucket}"
                                        s3-operations="s3Operations"
                                        credentials-ref="credentials"
                                        file-name-wildcard="${file-name-wildcard}"
                                        remote-directory="${remote-directory}"
                                        channel="splitChannel"
                                        local-directory="${local-directory}"
                                        accept-sub-folders="false"
                                        delete-source-files="true"
                                        archive-bucket="${archive-bucket}"
                                        archive-directory="${archive-directory}">
    </int-aws:s3-inbound-channel-adapter>

    int-file:splitter input-channel="splitChannel" output-channel="output" markers="true"/>

    <int:channel id="output"/>

    xd-shell>stream create feedTest16 --definition "aws-s3-source |processor| log" --deploy

Сообщение FileSplitter.FileMarker END будет содержать желаемое число строк.


person constantlearner    schedule 24.12.2015    source источник


Ответы (1)


Это невозможно; мы могли бы удалить маркер начала, но проблема в том, что мы не знаем, достигли ли мы конца файла, не выполняя следующее чтение (то есть, когда маркер конца выдается, если мы достигли EOF).

Вы можете добавить <filter/>, чтобы пропустить начальный маркер, но нет способа определить, что последнее «настоящее» сообщение действительно является последним.

Вы можете добавить преобразователь для преобразования маркера END, скажем, в пустую строку.

Мы могли бы, я полагаю, добавить опцию FileSplitter для упреждающего чтения, но сейчас этого не происходит.

Не стесняйтесь открывать проблему улучшения JIRA.

Вы также можете создать собственный сплиттер.

person Gary Russell    schedule 24.12.2015
comment
Мой вариант использования состоял в том, чтобы получить имя файла. Есть ли другой способ получить имя файла? - person constantlearner; 24.12.2015
comment
FileSplitter добавляет заголовок FileHeaders.FILENAME к каждому отправляемому сообщению, если ваша полезная нагрузка File или filePath. - person Artem Bilan; 24.12.2015
comment
Начиная с spring-integration 4.1.6 - что означает XD 1.2.1 или более позднюю версию. - person Gary Russell; 24.12.2015
comment
поэтому я устанавливаю маркеры в false и получаю имя файла в качестве заголовка - person constantlearner; 24.12.2015