我使用spring集成aws来轮询S3资源并从S3存储桶获取文件并使用spring集成来处理它们。 下面是我有:实现spring-integration-aws的问题
AmazonS3 amazonS3 = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey));
@Bean
IntegrationFlow fileReadingFlow() {
return IntegrationFlows
.from(s3InboundFileSynchronizingMessageSource(),
e -> e.poller(p -> p.fixedDelay(30, TimeUnit.SECONDS)))
.handle(receiptProcessor())
.get();
}
@Bean
public S3InboundFileSynchronizer s3InboundFileSynchronizer() {
S3InboundFileSynchronizer synchronizer = new S3InboundFileSynchronizer(amazonS3);
synchronizer.setDeleteRemoteFiles(false);
synchronizer.setPreserveTimestamp(true);
synchronizer.setRemoteDirectory(s3BucketName.concat("/").concat(s3InboundFolder));
synchronizer.setFilter(new S3RegexPatternFileListFilter(".*\\.dat\\.{0,1}\\d{0,2}"));
return synchronizer;
}
@Bean
public S3InboundFileSynchronizingMessageSource s3InboundFileSynchronizingMessageSource() {
S3InboundFileSynchronizingMessageSource messageSource =
new S3InboundFileSynchronizingMessageSource(s3InboundFileSynchronizer());
messageSource.setAutoCreateLocalDirectory(false);
messageSource.setLocalDirectory(new File(inboundDir));
messageSource.setLocalFilter(new AcceptOnceFileListFilter<File>());
return messageSource;
}
,我的S3存储和重点是:
bucketName = shipmentReceipts
key = receipts/originalReceipts/inbound/receipt1.dat
,所以我面临的2个问题与此实现:
1. inboundDir文件夹名称是使用s3key将其重命名为不同的路径名称,从而导致FileNotFoundException
。
protected void copyFileToLocalDirectory(String remoteDirectoryPath, F remoteFile, File localDirectory,
Session<F> session) throws IOException {
String remoteFileName = this.getFilename(remoteFile);
String localFileName = **this.generateLocalFileName(remoteFileName);**
String remoteFilePath = remoteDirectoryPath != null
? (remoteDirectoryPath + this.remoteFileSeparator + remoteFileName)
: remoteFileName;
if (!this.isFile(remoteFile)) {
if (this.logger.isDebugEnabled()) {
this.logger.debug("cannot copy, not a file: " + remoteFilePath);
}
return;
}
**File localFile = new File(localDirectory, localFileName);**
if (!localFile.exists()) {........
所以它结束了寻找一个文件路径C:\ SpringAws \ S3inbound \收据\ originalReceipts \入境\ receipt1.dat其中它不找到,并给出我AbstractInboundFileSynchronizer.java
文件追踪这对下面的代码那FileNotFoundException
错误。相反,它应该仅仅被复制到本地目录C:\ SpringAws \ S3inbound \ receipt1.dat
同时拉动S3对象我注意到它被拉动所有对象
shipmentReceipts/receipts
下代替shipmentReceipts/receipts/originalReceipts/inbound
在进一步调试我发现,在S3Session.java
下面的代码片段是负责IT:@Override public S3ObjectSummary[] list(String path) throws IOException { Assert.hasText(path, "'path' must not be empty String."); String[] bucketPrefix = path.split("/"); Assert.state(bucketPrefix.length > 0 && bucketPrefix[0].length() >= 3, "S3 bucket name must be at least 3 characters long."); String bucket = resolveBucket(bucketPrefix[0]); ListObjectsRequest listObjectsRequest = new ListObjectsRequest() .withBucketName(bucket); if (bucketPrefix.length > 1) { **listObjectsRequest.setPrefix(bucketPrefix[1]);** } /* For listing objects, Amazon S3 returns up to 1,000 keys in the response. If you have more than 1,000 keys in your bucket, the response will be truncated. You should always check for if the response is truncated. */ ObjectListing objectListing; List<S3ObjectSummary> objectSummaries = new ArrayList<>(); do {......
它集前缀一切后,第斜线/
遇到。 我如何减轻这些?谢谢!
谢谢阿尔乔姆!我确实使用了spring-integration-aws的1.1.0.M1版本,但仍然编写了自己的类来解决上述问题。 – user5758361
我正在使用Spring集成5.0.0.M4和Spring集成AWS 1.1.0.M2,并且在使用像'abc/def /'这样的存储桶名称时仍然存在相同的问题。有关解决方法,请参阅下面的答案。我是流媒体,所以没有可以操纵的本地文件名。 –
您是否介意提出GH问题,并提供更多详细信息以从我们这边复制?谢谢 –