簡體   English   中英

與AWS S3的Spring集成重試失敗的“獲取”文件

[英]spring-integration with AWS S3 retry failed “get” file

我們正在將彈簧與S3集成在一起。 我們有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獲取到重試同一文件的“獲取”請求?

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>

謝謝通用

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中提取。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM