已处理多条消息

时间:2016-01-20 15:24:56

标签: spring-integration spring-xd

我有一个spring xd源模块,它从s3中提取文件并逐行拆分。我的弹簧配置如下所示。但我有3个容器和1个管理服务器。现在我看到每个容器正在处理重复的消息他们每个人都在下载自己的副本。 我可以解决使源s3模块部署计数为1,但我的消息处理速度变慢。任何输入来解决这个问题?

   <int:poller fixed-delay="${fixedDelay}" default="true">
    <int:advice-chain>
            <ref bean="pollAdvise"/>

            </int:advice-chain>
    </int:poller>


    <bean id="pollAdvise" 

    </bean>






    <bean id="credentials" class="org.springframework.integration.aws.core.BasicAWSCredentials">
        <property name="accessKey" value="#{encryptedDatum.decryptBase64Encoded('${accessKey}')}"/>
        <property name="secretKey" value="${secretKey}"/>
    </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>

    <bean id="encryptedDatum" class="abc"/>

    <!-- 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="${fileNameWildcard}"
                                        remote-directory="${remoteDirectory}"
                                        channel="splitChannel"
                                        local-directory="${localDirectory}"
                                        accept-sub-folders="false"
                                        delete-source-files="true"
                                        archive-bucket="${archiveBucket}"
                                        archive-directory="${archiveDirectory}">
    </int-aws:s3-inbound-channel-adapter>

  <int-file:splitter input-channel="splitChannel" output-channel="output" markers="false" charset="UTF-8">

        <int-file:request-handler-advice-chain>
            <bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
                <property name="onSuccessExpression" value="payload.delete()"/>
            </bean>
        </int-file:request-handler-advice-chain>

</int-file:splitter>

    <int:channel id="output"/>

[更新] 我添加了你使用元数据存储建议的幂等性。但是因为我的xd在3容器集群中运行,兔子将简单的metadatastore工作吗?我想我应该使用reds / mongo元数据源。如果我使用mongo / redis metadatastore怎么办我逐出/删除邮件,因为邮件会随着时间的推移堆积起来?

<int:idempotent-receiver id="expressionInterceptor" endpoint="output"
                              metadata-store="store"
                             discard-channel="nullChannel"
                             throw-exception-on-rejection="false"
                              key-expression="payload"/>

    <bean id="store" class="org.springframework.integration.metadata.SimpleMetadataStore"/>

1 个答案:

答案 0 :(得分:1)

我建议你看看Idempotent Receiver

使用它可以使用共享MetadataStore并且不接受重复文件。

应为<idempotent-receiver>配置<int-file:splitter>。是的:使用丢弃逻辑来避免重复消息。

<强>更新

  

。但是因为我的xd在3个容器集群中运行,所以兔子会简单地进行metadatastore工作吗?

这无关紧要,因为您从S3 MessageSource启动流,因此您应该过滤那里的文件。因此,您需要外部共享MetadataStore

  

。如果我使用mongo / redis metadatastore,我怎么能逐出/删除这些消息,因为消息会随着时间的推移堆积起来?

这是对的。它是Idempotent接收器逻辑的副作用。如果您使用DataBase,不确定它是如何出现问题的......

您可以通过某些定期任务清理集合/键。也许每周一次......

相关问题