Created
October 3, 2019 11:44
-
-
Save MemoAlfa/950ba265b8bad2ce690f371f69c5587e to your computer and use it in GitHub Desktop.
Override the Lazy initialized beans by the ones that are pointing to localstack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean(destroyMethod = "shutdown") | |
@Primary | |
public AmazonSQS getSqsClient(@Value("${localstack.host}") String sqsHost, @Value("${localstack.tcp.4576}") String port) { | |
final AmazonSQSAsync sqsClient = | |
AmazonSQSAsyncClientBuilder.standard() | |
.withEndpointConfiguration( | |
new AwsClientBuilder.EndpointConfiguration(sqsHost + ":" + port, "cn-north-1")) | |
.withClientConfiguration(new ClientConfiguration().withProtocol(Protocol.HTTP)).build(); | |
return sqsClient; | |
} | |
@Bean(destroyMethod = "shutdown") | |
@Primary | |
public AmazonS3 getS3Client(@Value("${localstack.host}") String s3Host, | |
@Value("${localstack.tcp.4572}") String port, | |
@Value("${s3.userDocuments.bucketName}") String userDocumentsBucket) { | |
final String signingRegion = "cn-north-1"; | |
final AmazonS3 s3Client = | |
AmazonS3ClientBuilder.standard() | |
.withEndpointConfiguration( | |
new AwsClientBuilder.EndpointConfiguration(s3Host + ":" + port, signingRegion)) | |
.withClientConfiguration(new ClientConfiguration().withProtocol(Protocol.HTTP)) | |
.withPathStyleAccessEnabled(true) | |
.disableChunkedEncoding() | |
.build(); | |
s3Client.createBucket(userDocumentsBucket); | |
log.info("created bucket with name " + userDocumentsBucket); | |
return s3Client; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment