I am working on a project where I am required to poll S3 bucket for files and upload in a different S3 bucket. As a first step to implementing it, I am trying to poll S3 bucket for new files created and create them in my local directory using Spring Integration. To achieve that I have created a simple spring-boot application with maven with the below object polling configuration while handles the fileReading IntegrationFlow
@Configuration
@EnableIntegration
@IntegrationComponentScan
@EnableAsync
public class ObjectPollerConfiguration {
@Value("${amazonProperties.bucketName}")
private String bucketName;
public static final String OUTPUT_DIR2 = "target2";
@Autowired
private AmazonClient amazonClient;
@Bean
public S3InboundFileSynchronizer s3InboundFileSynchronizer() {
S3InboundFileSynchronizer synchronizer = new S3InboundFileSynchronizer(amazonClient.getS3Client());
synchronizer.setDeleteRemoteFiles(true);
synchronizer.setPreserveTimestamp(true);
synchronizer.setRemoteDirectory(bucketName);
return synchronizer;
}
@Bean
@InboundChannelAdapter(value = "s3FilesChannel", poller = @Poller(fixedDelay = "30"))
public S3InboundFileSynchronizingMessageSource s3InboundFileSynchronizingMessageSource() {
S3InboundFileSynchronizingMessageSource messageSource =
new S3InboundFileSynchronizingMessageSource(s3InboundFileSynchronizer());
messageSource.setAutoCreateLocalDirectory(true);
messageSource.setLocalDirectory(new File("."));
messageSource.setLocalFilter(new AcceptOnceFileListFilter<File>());
return messageSource;
}
@Bean
public PollableChannel s3FilesChannel() {
return new QueueChannel();
}
@Bean
IntegrationFlow fileReadingFlow() {
return IntegrationFlows
.from(s3InboundFileSynchronizingMessageSource(),
e -> e.poller(p -> p.fixedDelay(30, TimeUnit.SECONDS)))
.handle(fileProcessor())
.get();
}
@Bean
public MessageHandler fileProcessor() {
FileWritingMessageHandler handler = new FileWritingMessageHandler(new File(OUTPUT_DIR2));
handler.setExpectReply(false); // end of pipeline, reply not needed
return handler;
}
}*
But when I start my application as a java application and upload files to S3, I don't see the target2 directory with file nor getting any logs corresponding to polling execution. Can someone help me to get it working ?
I think the problem that you don't use your OUTPUT_DIR2
property for local dir to push into.
Your code for local dir is like this:
messageSource.setLocalDirectory(new File("."));
This is fully not what you are looking for. Try to change it into the
messageSource.setLocalDirectory(new File(OUTPUT_DIR2));