nicolas
nicolas

Reputation: 121

Configure Amazon SQS queue name in Spring Boot

I'm using AmazonSQS & Spring Boot (spring-cloud-aws-messaging). I've configured a message listener to receive messages from the queue with the annotation @SqsListener.

@SqsListener(value = "indexerQueue", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
public void queueListener(String rawMessage) {
   ...
}

This is a very simple approach but I didn't find the way to make the queue name load from a configuration file because I have different environments. Any ideas on this regard?

Upvotes: 9

Views: 11349

Answers (1)

Miloš Milivojević
Miloš Milivojević

Reputation: 5369

What version of spring-cloud-aws-messaging are you using? Version 1.1 should allow you to use a placeholder as a queue name, e.g.

@SqsListener(value = "${sqs.queue.indexer}", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
public void queueListener(String rawMessage) {
   ...
}

Then, in your application-env.properties files you can put different values. For instance in application-dev.properties:

sqs.queue.indexer=devIndexerQueue

and in application-production.properties

sqs.queue.indexer=indexerQueue

Upvotes: 27

Related Questions