InboundChannelAdapter从s3多次拾取同一文件

时间:2018-10-31 12:33:08

标签: spring amazon-s3 spring-integration spring-integration-aws

我已将 InboundChannelAdapter 配置为 S3StreamingMessageSource 。 我强迫 Poller 仅使用1个线程使用 taskExecutor 。但是我看到同一线程以3-4秒的间隔将同一文件提取了3次。即使轮询间隔为10秒。我指定了由模式过滤器和acceptoncefilter组成的Composite过滤器。但是没有结果,文件总是被拾取3次。

String prefix = "some_prefix";
String channel = "some_channel"
Pattern filePattern = Pattern.compile(
            "^" + prefix + "some_file_name_pattern");
@Bean
@InboundChannelAdapter(value = channel,
        poller = @Poller(fixedDelay = "10000", taskExecutor = "threadPoolTaskExecutor"))
public MessageSource<InputStream> createS3InboundStreamingMessageSource() {
    S3StreamingMessageSource messageSource = new S3StreamingMessageSource(template());
    messageSource.setRemoteDirectory(bucketName);
    CompositeFileListFilter<S3ObjectSummary> compositeFileListFilter = new ChainFileListFilter<>();
    compositeFileListFilter.addFilter(new S3PersistentAcceptOnceFileListFilter(
            new SimpleMetadataStore(), prefix));
    compositeFileListFilter.addFilter(new S3RegexPatternFileListFilter(filePattern));
    messageSource.setFilter(compositeFileListFilter);
    return messageSource;
}

@Transformer(inputChannel = channel,"another_channel")
public Message<S3ObjectInputStream> enrich(Message<S3ObjectInputStream> s3ObjectInputStreamMessage) {
    S3ObjectInputStream s3ObjectInputStream = s3ObjectInputStreamMessage.getPayload();
    URI zipUri = s3ObjectInputStream.getHttpRequest().getURI();
    LOGGER.info("Picking up file : {}", zipUri.getPath());
    ...
}

 private S3RemoteFileTemplate template() {
    S3SessionFactory sessionFactory = new S3SessionFactory(amazonS3);
    return new S3RemoteFileTemplate(sessionFactory);
}

@Bean
public TaskExecutor threadPoolTaskExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setMaxPoolSize(1);
    executor.setThreadNamePrefix("single_thread_task_executor");
    executor.initialize();
    return executor;
}

我看到该应用访问了@Transformer 3次。非常感谢您的帮助。

0 个答案:

没有答案