0

I was trying to create a SQS queue listener in my spring boot app using the code below

AmazonSQSAsyncClient amazonSQSAsyncClient= new AmazonSQSAsyncClient(getProfileCredentialsProvider());

However AmazonSQSAsyncClient seems to be deprecated. Is there a different way of using builder to create this object?

Punter Vicky
  • 15,954
  • 56
  • 188
  • 315

2 Answers2

2

How about this?

AmazonSQSAsyncClientBuilder.standard()
                .withCredentials(getProfileCredentialsProvider())
                .build();

That is really mentioned in the JavaDocs:

* @deprecated use {@link AmazonSQSAsyncClientBuilder#withCredentials(AWSCredentialsProvider)}
 */
@Deprecated
public AmazonSQSAsyncClient(AWSCredentialsProvider awsCredentialsProvider) {
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
1

For those of you looking for standard way of defining listeners.

Include spring-cloud-aws-messaging in your application, beware to not include the spring-cloud-aws-started-messaging.

Then you gain access to two ways of creating listeners:

@SqsListener(value = "logical queue name")

and programatically

@Autowired
private SimpleMessageListenerContainer simpleMessageListenerContainer;
...
simpleMessageListenerContainer.start("logical queue name");

spring will handle the creating of AmazonSQS client for you.

NOTE: for the @SqsListener annotation you need @EnableSqs

Borislav Stoilov
  • 3,247
  • 2
  • 21
  • 46