Created
August 22, 2022 14:42
-
-
Save bitkill/53b02040943178e8f199476b6b082329 to your computer and use it in GitHub Desktop.
[custom config aws sdk v2 sqs for java] sqs
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
dependencyManagement { | |
imports { | |
mavenBom("software.amazon.awssdk:bom:2.5.5") | |
} | |
} | |
dependencies { | |
implementation("software.amazon.awssdk:sqs") | |
} |
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
import lombok.extern.slf4j.Slf4j; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.context.annotation.Primary; | |
import org.springframework.context.annotation.Profile; | |
import software.amazon.awssdk.auth.credentials.AwsCredentials; | |
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; | |
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; | |
import software.amazon.awssdk.regions.Region; | |
import software.amazon.awssdk.services.sqs.SqsAsyncClient; | |
import java.net.URI; | |
@Slf4j | |
@Configuration | |
public class ReactiveSQSConfig { | |
@Value("${cloud.aws.sqs.endpoint:#{null}}") | |
String endpoint; | |
@Value("${cloud.aws.sqs.region}") | |
String region; | |
@Value("${cloud.aws.credentials.access-key}") | |
String accessKey; | |
@Value("${cloud.aws.credentials.secret-key}") | |
String secretKey; | |
@Bean | |
@Primary | |
@Profile("(local || default || secrets) && !test") | |
public SqsAsyncClient amazonSQSAsyncClientLocal() { | |
return SqsAsyncClient.builder() | |
.endpointOverride(URI.create(endpoint)) | |
.region(Region.EU_WEST_1) | |
.credentialsProvider(StaticCredentialsProvider.create(new AwsCredentials() { | |
@Override | |
public String accessKeyId() { | |
return accessKey; | |
} | |
@Override | |
public String secretAccessKey() { | |
return secretKey; | |
} | |
})) | |
.build(); | |
} | |
@Bean | |
@Profile("!local && !default && !test && !secrets") | |
public SqsAsyncClient amazonSQSAsyncClient() { | |
return SqsAsyncClient.builder() | |
.endpointOverride(URI.create(endpoint)) | |
.region(Region.EU_WEST_1) | |
.credentialsProvider(DefaultCredentialsProvider.create()) | |
.build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment