如何保持多个实例之间的文件同步?这样只有一个实例可以提取文件并进行处理

时间:2018-06-26 15:32:53

标签: amazon-web-services amazon-s3 spring-integration amazon-sqs

我有一个使用Spring Integration的应用程序。我的应用程序从S3存储桶中侦听,如果有新文件可用,它将处理这些文件

现在,如果我只有一个应用程序实例,则此方案将顺利进行。在多个实例的情况下,文件可能被多个应用程序实例处理。可以在这里完成什么工作,以便只有一个实例可以处理我的文件?我错过了Spring Integration中的一个内置属性,可以用来维持同步吗?我们可以对S3存储桶对象执行锁定机制吗?

P.S Quartz和Zookeeper可以在这里使用,但我想看看在这里可以使用其他什么替代方法

1 个答案:

答案 0 :(得分:0)

为此,Spring Integration建议:

 * Persistent file list filter using the server's file timestamp to detect if we've already
 * 'seen' this file.
 *
 * @author Artem Bilan
 */
public class S3PersistentAcceptOnceFileListFilter extends AbstractPersistentAcceptOnceFileListFilter<S3ObjectSummary> {

因此,您可以配置S3InboundFileSynchronizer,可以通过以下方式提供此S3PersistentAcceptOnceFileListFilter

/**
 * Set the filter to be applied to the remote files before transferring.
 * @param filter the file list filter.
 */
public void setFilter(FileListFilter<F> filter) {

必须为任何可能的共享持久S3PersistentAcceptOnceFileListFilter实现配置MetadataStorehttps://docs.spring.io/spring-integration/docs/5.0.6.RELEASE/reference/html/system-management-chapter.html#metadata-store

例如,从版本1.1开始,Spring Integration AWS提供了以下功能:

/**
 * The {@link ConcurrentMetadataStore} for the {@link AmazonDynamoDB}.
 *
 * @author Artem Bilan
 *
 * @since 1.1
 */
public class DynamoDbMetaDataStore implements ConcurrentMetadataStore, InitializingBean {

P.S。尽管您的问题中没有关于Apache Camel的信息...