My scenario is to transfer one file from AWS S3 bucket to EC2 instance only once whenever the file gets modified. I used the following configuration and manually started the adapter when server starts.
The issue is the execution is repeated 5 or 6 times when server starts. Looks like different threads execution are happening. I am able to see different task-executor in the log don't know whether its a poller issue or adapter issue.
I am using service activator to do some other operation based on the file change in S3 location.
Note : This issue is happening only once on start up . It's working fine further file modification.
Config:
<bean id="s3SessionFactory"
class="org.springframework.integration.aws.support.S3SessionFactory"></bean>
<bean id="acceptOnceFilter"
class="org.springframework.integration.file.filters.AcceptOnceFileListFilter" />
<task:executor id="s3PollingExecutor" pool-size="1" queue-capacity="10" />
<integration:channel id="s3FilesChannel"/>
<int-aws:s3-inbound-channel-adapter id="s3FileInbound"
channel="s3FilesChannel"
session-factory="s3SessionFactory"
auto-create-local-directory="false"
delete-remote-files="false"
preserve-timestamp="true"
filter="acceptOnceFilter"
local-directory="local_directory"
auto-startup="false"
remote-directory="s3_bucket">
<integration:poller id="s3FilesChannelPoller"
fixed-rate="1000"
max-messages-per-poll="1" time-unit="MILLISECONDS"
task-executor="s3PollingExecutor">
</integration:poller>
</int-aws:s3-inbound-channel-adapter>
<integration:service-activator id="s3FilesChannelWatcher"
input-channel="s3FilesChannel"
output-channel="nullChannel"
ref="configurationFileWatcher"
method="getConfigurationFileWatcher">
</integration:service-activator>
As you suggested i have tried the following .
<bean id="acceptOnceFilterRegion"
class="cS3FileFilterOnLastModifiedTime">
<constructor-arg index="0" ref="metaDataStoreRegion"/>
<constructor-arg index="1" value="*"/>
</bean>
logic added for checking last modified time
import org.springframework.integration.aws.support.filters.S3PersistentAcceptOnceFileListFilter;
import org.springframework.integration.metadata.ConcurrentMetadataStore;
import com.amazonaws.services.s3.model.S3ObjectSummary;
public class S3FileFilterOnLastModifiedTime extends S3PersistentAcceptOnceFileListFilter {
Long delayTime = 1000L;
public S3FileFilterOnLastModifiedTime(ConcurrentMetadataStore store, String prefix) {
super(store, prefix);
}
@Override
public boolean accept(S3ObjectSummary file) {
long lastModified = modified(file);
long currentTime = System.currentTimeMillis();
long timeDifference = currentTime - lastModified;
return timeDifference > delayTime;
}
}
Still no hopes .logs are like this .......
[INFO ] 2018-10-11 11:22:10,888 [s3PollingExecutor-1] ConfigurationSettingWatcher {} - ConfigurationSettingWatcher Started succesfully
[INFO ] 2018-10-11 11:22:10,892 [s3PollingExecutor-2] ConfigurationSettingWatcher {} - ConfigurationSettingWatcher Started succesfully
[INFO ] 2018-10-11 11:22:10,892 [s3PollingExecutor-3] ConfigurationSettingWatcher {} - ConfigurationSettingWatcher Started succesfully
[INFO ] 2018-10-11 11:22:10,893 [s3PollingExecutor-4] ConfigurationSettingWatcher {} - ConfigurationSettingWatcher Started succesfully
[INFO ] 2018-10-11 11:22:10,893 [s3PollingExecutor-5] ConfigurationSettingWatcher {} - ConfigurationSettingWatcher Started succesfully
[INFO ] 2018-10-11 11:22:10,894 [s3PollingExecutor-6] ConfigurationSettingWatcher {} - ConfigurationSettingWatcher Started succesfully