与AWS S3重试的spring-integration失败了“get”文件

问题描述 投票:0回答:1

我们正在使用与Spring的Spring集成。我们有s3-inbound-streaming-channel-adapter从S3读取。发生的事情是,如果“get”失败,则s3-inbound-streaming-channel-adapter将文件名放在“acceptOnceFilter”中,并且在失败时不重试。

Q1。我们想要的是当s3-inbound-streaming-channel-adapter“获取”来自S3的文件并说由于某种原因这个“获取”失败...我们如何获得s3-inbound-streaming-channel-adapter to再次为同一个文件重试这个“获取”请求?

Q2。失败时,会从s3-inbound-streaming-channel-adapter向默认“errorChannel”发送异常。异常中的消息是否包含失败的“文件名”?

<int:channel id="s3FileProcessingChannel">
  <int:queue capacity="15"/>
</int:channel>

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

<bean id="acceptOnceFilter"
  class="org.springframework.integration.aws.support.filters.S3PersistentAcceptOnceFileListFilter">
  <constructor-arg index="0" ref="metadataStore"/>
  <constructor-arg index="1" value="streaming"/>
</bean>

<int-aws:s3-inbound-streaming-channel-adapter id="s3Region1"
channel="s3FileProcessingChannel" 
session-factory="s3SessionFactory"
filter="acceptOnceFilter"
remotedirectoryexpression="'${s3.sourceBucket}/emm'">

  <int:poller fixed-delay="1000" max-messages-per-poll="15"/>
</int-aws:s3-inbound-streaming-channel-adapter>

谢谢GM

spring-boot spring-integration spring-integration-aws
1个回答
1
投票

S3PersistentAcceptOnceFileListFilter实施:

/**
 * A {@link FileListFilter} that can be reset by removing a specific file from its
 * state.
 * @author Gary Russell
 * @since 4.1.7
 *
 */
public interface ResettableFileListFilter<F> extends FileListFilter<F> {

    /**
     * Remove the specified file from the filter so it will pass on the next attempt.
     * @param f the element to remove.
     * @return true if the file was removed as a result of this call.
     */
    boolean remove(F f);

}

并且S3StreamingMessageSource填充这些标题:

return getMessageBuilderFactory()
                    .withPayload(session.readRaw(remotePath))
                    .setHeader(IntegrationMessageHeaderAccessor.CLOSEABLE_RESOURCE, session)
                    .setHeader(FileHeaders.REMOTE_DIRECTORY, file.getRemoteDirectory())
                    .setHeader(FileHeaders.REMOTE_FILE, file.getFilename())
                    .setHeader(FileHeaders.REMOTE_FILE_INFO,
                            this.fileInfoJson ? file.toJson() : file);

当发生错误时,您只需要使用FileHeaders.REMOTE_FILE来调用remove()上方的提及,并且您的失败文件将在下一个轮询周期从S3中获取。

© www.soinside.com 2019 - 2024. All rights reserved.