【问题标题】:spring integration file splitter sending file markers as payloadspring 集成文件拆分器将文件标记作为有效负载发送
【发布时间】:2015-12-24 16:53:00
【问题描述】:

我有 spring xd 源模块,它逐行拆分文本文件。我想查看文件名并计算文件中的行数,因此我使用带有文件标记的文件拆分器。但问题是如果我有一个记录文件,文件计数作为有效负载来,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 消息将包含所需的行数。

【问题讨论】:

    标签: spring-integration spring-xd


    【解决方案1】:

    这是不可能的;我们可以消除开始标记,但问题是我们不知道我们已经到达文件末尾而不进行下一次读取(如果我们到达 EOF,则发出结束标记)。

    您可以添加&lt;filter/&gt; 来跳过开始标记,但无法确定最后一条“真实”消息确实是最后一条。

    您可以添加一个转换器来将 END 标记转换为空字符串。

    我想,我们可以在FileSplitter 中添加一个选项以进行预读,但现在不能这样做。

    随时打开Improvement JIRA Issue

    您还可以创建自定义拆分器。

    【讨论】:

    • 我的用例是获取文件名还有其他方法可以获取文件名吗?
    • FileSplitterFileHeaders.FILENAME 标头添加到每个发出的消息,如果您的有效负载是FilefilePath
    • spring-integration 4.1.6 - 这意味着 XD 1.2.1 或更高版本。
    • 所以我将标记设置为 false 并将文件名作为标题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多