You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Copy all the S3 functionality from the Spring Integration AWS project
* Document the feature
* Add `spring-cloud-aws-starter-integration-s3` convenient module
* Introduce `LocalstackContainerTest` in the tests, similar to the one in DynamoDB module.
Reuse this abstraction for all the S3 integration tests to avoid unnecessary LocalStack container restarts
while we running all the tests in module
Copy file name to clipboardExpand all lines: docs/src/main/asciidoc/s3.adoc
+146Lines changed: 146 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -641,3 +641,149 @@ Sample IAM policy granting access to `spring-cloud-aws-demo` bucket:
641
641
]
642
642
}
643
643
----
644
+
645
+
=== Spring Integration Support
646
+
647
+
Starting with version 4.0, Spring Cloud AWS provides https://spring.io/projects/spring-integration[Spring Integration] channel adapters for Amazon SQS.
648
+
649
+
The S3 Channel Adapters are based on the `S3Client` template and `S3TransferManager`.
650
+
See their specification and Javadocs for more information.
651
+
652
+
The S3 Inbound Channel Adapter is represented by the `S3InboundFileSynchronizingMessageSource` and allows pulling S3 objects as files from the S3 bucket to the local directory for synchronization.
653
+
This adapter is fully similar to the Inbound Channel Adapters in the FTP and SFTP Spring Integration modules.
654
+
See more information in the https://docs.spring.io/spring-integration/reference/ftp.html[FTP/FTPS Adapters Chapter] for common options or `SessionFactory`, `RemoteFileTemplate` and `FileListFilter` abstractions.
655
+
656
+
The Java Configuration is:
657
+
658
+
[source,java]
659
+
----
660
+
@SpringBootApplication
661
+
public static class MyConfiguration {
662
+
663
+
@Autowired
664
+
private S3Client amazonS3;
665
+
666
+
@Bean
667
+
public S3InboundFileSynchronizer s3InboundFileSynchronizer() {
668
+
S3InboundFileSynchronizer synchronizer = new S3InboundFileSynchronizer(this.amazonS3);
With this config you receive messages with `java.io.File` `payload` from the `s3FilesChannel` after periodic synchronization of content from the Amazon S3 bucket into the local directory.
697
+
698
+
The `S3StreamingMessageSource` adapter produces messages with payloads of type `InputStream`, allowing S3 objects to be fetched without writing to the local file system.
699
+
Since the session remains open, the consuming application is responsible for closing the session when the file has been consumed.
700
+
The session is provided in the closeableResource header (`IntegrationMessageHeaderAccessor.CLOSEABLE_RESOURCE`).
701
+
Standard framework components, such as the `FileSplitter` and `StreamTransformer` will automatically close the session.
702
+
703
+
The following Spring Boot application provides an example of configuring the S3 inbound streaming adapter using Java configuration:
704
+
705
+
[source,java]
706
+
----
707
+
@SpringBootApplication
708
+
public class S3JavaApplication {
709
+
710
+
public static void main(String[] args) {
711
+
new SpringApplicationBuilder(S3JavaApplication.class)
public org.springframework.integration.transformer.Transformer transformer() {
732
+
return new StreamTransformer();
733
+
}
734
+
735
+
@Bean
736
+
public S3RemoteFileTemplate template() {
737
+
return new S3RemoteFileTemplate(new S3SessionFactory(this.amazonS3));
738
+
}
739
+
740
+
@Bean
741
+
public PollableChannel s3Channel() {
742
+
return new QueueChannel();
743
+
}
744
+
}
745
+
----
746
+
747
+
> NOTE: Unlike the non-streaming inbound channel adapter, this adapter does not prevent duplicates by default.
748
+
> If you do not delete the remote file and wish to prevent the file being processed again, you can configure an `S3PersistentFileListFilter` in the `filter` attribute.
749
+
> If you don’t want to persist the state, an in-memory `SimpleMetadataStore` can be used with the filter.
750
+
> If you wish to use a filename pattern (or regex) as well, use a `CompositeFileListFilter`.
751
+
752
+
The `S3MessageHandler` is an Outbound Channel Adapter and allows performing `upload`, `download` and `copy` (see `S3MessageHandler.Command` enum) operations in the provided S3 bucket.
return new S3MessageHandler(this.amazonS3, "my-bucket");
768
+
}
769
+
770
+
}
771
+
----
772
+
773
+
With this config you can send a message with the `java.io.File` as `payload` and the `transferManager.upload()` operation will be performed, where the file name is used as a S3 Object key.
774
+
775
+
See more information in the `S3MessageHandler` JavaDocs.
776
+
777
+
NOTE: The AWS SDK recommends to use `S3CrtAsyncClient` for `S3TransferManager`, therefore an `S3AsyncClient.crtBuilder()` has to be used to achieve respective upload and download requirements, what is done internally in the `S3MessageHandler` when `S3CrtAsyncClient`-based constructor is used.
778
+
779
+
The `S3MessageHandler` can be used as an Outbound Gateway with the `produceReply = true` constructor argument for Java Configuration.
780
+
781
+
The "request-reply" nature of this gateway is async and the `Transfer` result from the `TransferManager` operation is sent to the `outputChannel`, assuming the transfer progress observation in the downstream flow.
782
+
783
+
The `TransferListener` can be supplied to the `S3MessageHandler` to track the transfer progress per requests.
784
+
785
+
See more information in the `S3MessageHandler` Javadocs.
786
+
787
+
The Spring Integration dependency (as well as `s3-transfer-manager` and `aws-crt-client`) in the `spring-cloud-aws-s3` module are `optional` to avoid unnecessary artifacts on classpath when Spring Integration is not used.
788
+
For convenience, a dedicated `spring-cloud-aws-starter-integration-s3` is provided managing all the required dependencies for Spring Integration support with Amazon S3.
0 commit comments