Mention AWS CRT client in the README

* Use an explicit `S3AsyncClient.crtBuilder()` according to the warning in the logs for test
* Some code clean up in the `S3MessageHandler`
This commit is contained in:
Artem Bilan
2023-09-21 10:20:32 -04:00
parent f184d7be29
commit 0b41aa23d8
3 changed files with 11 additions and 9 deletions

View File

@@ -48,6 +48,7 @@ These dependencies are optional in the project:
* `com.amazonaws:amazon-kinesis-producer` - for KPL-based `MessageHandler`
* `software.amazon.awssdk:dynamodb` - for `DynamoDbMetadataStore` and `DynamoDbLockRegistry`
* `software.amazon.awssdk:s3-transfer-manager` - for `S3MessageHandler`
* `software.amazon.awssdk:aws-crt-client` - for `S3MessageHandler`
Consider to include an appropriate dependency into your project when you use particular component from this project.
@@ -188,6 +189,8 @@ With this config you can send a message with the `java.io.File` as `payload` and
See more information in the `S3MessageHandler` JavaDocs.
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.
### Outbound Gateway
The S3 Outbound Gateway is represented by the same `S3MessageHandler` with the `produceReply = true` constructor argument for Java Configuration.

View File

@@ -36,7 +36,6 @@ import software.amazon.awssdk.transfer.s3.model.Transfer;
import software.amazon.awssdk.transfer.s3.model.UploadDirectoryRequest;
import software.amazon.awssdk.transfer.s3.model.UploadRequest;
import software.amazon.awssdk.transfer.s3.progress.TransferListener;
import software.amazon.awssdk.utils.BinaryUtils;
import software.amazon.awssdk.utils.IoUtils;
import software.amazon.awssdk.utils.Md5Utils;
@@ -52,7 +51,6 @@ import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandlingException;
import org.springframework.util.Assert;
import org.springframework.util.DigestUtils;
/**
* The {@link AbstractReplyProducingMessageHandler} implementation for the Amazon S3
@@ -298,16 +296,14 @@ public class S3MessageHandler extends AbstractReplyProducingMessageHandler {
if (payload instanceof InputStream inputStream) {
byte[] body = IoUtils.toByteArray(inputStream);
if (putObjectRequest.contentMD5() == null) {
byte[] md5Digest = DigestUtils.md5Digest(body);
putObjectRequestBuilder.contentMD5(BinaryUtils.toBase64(md5Digest));
putObjectRequestBuilder.contentMD5(Md5Utils.md5AsBase64(body));
inputStream.reset();
}
requestBody = AsyncRequestBody.fromBytes(body);
}
else if (payload instanceof File fileToUpload) {
if (putObjectRequest.contentMD5() == null) {
String contentMd5 = Md5Utils.md5AsBase64(fileToUpload);
putObjectRequestBuilder.contentMD5(contentMd5);
putObjectRequestBuilder.contentMD5(Md5Utils.md5AsBase64(fileToUpload));
}
if (putObjectRequest.contentLength() == null) {
putObjectRequestBuilder.contentLength(fileToUpload.length());
@@ -320,8 +316,7 @@ public class S3MessageHandler extends AbstractReplyProducingMessageHandler {
}
else if (payload instanceof byte[] payloadBytes) {
if (putObjectRequest.contentMD5() == null) {
String contentMd5 = Md5Utils.md5AsBase64(payloadBytes);
putObjectRequestBuilder.contentMD5(contentMd5);
putObjectRequestBuilder.contentMD5(Md5Utils.md5AsBase64(payloadBytes));
}
if (putObjectRequest.contentLength() == null) {
putObjectRequestBuilder.contentLength((long) payloadBytes.length);

View File

@@ -78,7 +78,11 @@ public interface LocalstackContainerTest {
}
static S3AsyncClient s3AsyncClient() {
return applyAwsClientOptions(S3AsyncClient.builder());
return S3AsyncClient.crtBuilder()
.region(Region.of(LOCAL_STACK_CONTAINER.getRegion()))
.credentialsProvider(credentialsProvider())
.endpointOverride(LOCAL_STACK_CONTAINER.getEndpoint())
.build();
}
static S3Client s3Client() {