This repository was archived by the owner on Jan 19, 2022. It is now read-only.
-
Couldn't load subscription status.
- Fork 365
This repository was archived by the owner on Jan 19, 2022. It is now read-only.
How to initialize multiple AmazonSQSAsync with different credentials? #627
Copy link
Copy link
Closed
Labels
Description
Describe the bug
I have a service which has to receive messages from one queue and write some messages to another queue.
After configuring sqs-related stuff and running the service I get the following error:
Field awsCredentialsProvider in org.springframework.cloud.aws.messaging.config.annotation.SqsClientConfiguration required a single bean, but 2 were found:
- managementAwsCredentialsProvider: defined by method 'managementAwsCredentialsProvider' in class path resource [...managementAwsConfiguration.class]
- changeAwsCredentialsProvider: defined by method 'changeAwsCredentialsProvider' in class path resource [.../changeAwsConfiguration.class]
Spring cloud version:
Spring-cloud 2.1.3.RELEASE
Sample
First config which receives messages:
@Configuration
@EnableSqs
public class ManagementAwsConfiguration {
@Bean
public SQSConnectionFactory sqsConnectionFactory(@Qualifier("management") AmazonSQSAsync amazonSQS) {
return new SQSConnectionFactory(new ProviderConfiguration(), amazonSQS);
}
@Bean
public QueueMessagingTemplate queueMessagingTemplate(@Qualifier("management") AmazonSQSAsync amazonSQSAsync) {
return new QueueMessagingTemplate(amazonSQSAsync);
}
@Bean
@Qualifier("management")
public AWSCredentialsProvider managementAwsCredentialsProvider(AWSCredentialsStore awsCredentialsStore) {
return awsCredentialsStore.getAWSCredentialsProvider("management");
}
@Bean
@Qualifier("management")
public AmazonSQSAsync managementAmazonSQS(@Qualifier("management") AWSCredentialsProvider awsCredentialsProvider) {
return AmazonSQSAsyncClientBuilder.standard()
.withCredentials(awsCredentialsProvider)
.withRegion(Regions.EU_CENTRAL_1)
.build();
}
}
second config which sends messages:
@Configuration
@EnableSqs
public class ChangeAwsConfiguration {
@Bean
@Qualifier("change")
public AWSCredentialsProvider changeAwsCredentialsProvider(AWSCredentialsStore awsCredentialsStore) {
return awsCredentialsStore.getAWSCredentialsProvider("change");
}
@Bean
@Qualifier("change")
public AmazonSQS futureStockChangeAmazonSQS(@Qualifier("change") AWSCredentialsProvider awsCredentialsProvider) {
return AmazonSQSClient.builder()
.withCredentials(awsCredentialsProvider)
.withRegion(Regions.EU_CENTRAL_1)
.build();
}
}
By looking at SqsClientConfiguration in spring sources it doesn't look like there is a straightforward way to configure two SQS instances, is there a way to do that?