CAMEL-8431 Fixed the issue that camel-aws consume the same files in aws S3 bucket where deleteAfterRead = false with thanks to Yap
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e75356c3 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e75356c3 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e75356c3 Branch: refs/heads/camel-2.13.x Commit: e75356c31e1fa0157420080516b0309d59bf9c27 Parents: 8131862 Author: Willem Jiang <[email protected]> Authored: Wed Mar 4 20:59:22 2015 +0800 Committer: Willem Jiang <[email protected]> Committed: Wed Mar 4 21:54:12 2015 +0800 ---------------------------------------------------------------------- .../org/apache/camel/component/aws/s3/S3Consumer.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/e75356c3/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Consumer.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Consumer.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Consumer.java index 3289d36..73656e4 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Consumer.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Consumer.java @@ -48,6 +48,7 @@ import org.slf4j.LoggerFactory; public class S3Consumer extends ScheduledBatchPollingConsumer { private static final Logger LOG = LoggerFactory.getLogger(S3Consumer.class); + private String marker; public S3Consumer(S3Endpoint endpoint, Processor processor) throws NoFactoryAvailableException { super(endpoint, processor); @@ -75,9 +76,16 @@ public class S3Consumer extends ScheduledBatchPollingConsumer { listObjectsRequest.setBucketName(bucketName); listObjectsRequest.setPrefix(getConfiguration().getPrefix()); listObjectsRequest.setMaxKeys(maxMessagesPerPoll); + if (marker != null && !getConfiguration().isDeleteAfterRead()) { + listObjectsRequest.setMarker(marker); + } ObjectListing listObjects = getAmazonS3Client().listObjects(listObjectsRequest); - + // we only setup the marker if the file is not deleted + if (!getConfiguration().isDeleteAfterRead()) { + // where marker is track + marker = listObjects.getMarker(); + } if (LOG.isTraceEnabled()) { LOG.trace("Found {} objects in bucket [{}]...", listObjects.getObjectSummaries().size(), bucketName); }
