9

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?

Praveen Kumar K S
  • 3,024
  • 1
  • 24
  • 31
nicolas
  • 121
  • 1
  • 7

1 Answers1

26

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
Miloš Milivojević
  • 5,219
  • 3
  • 26
  • 39
  • how can we set the name if using properties file is not an option? We use CloudFoundry and the name can only be fetch using CfEnv at startup time – xbmono Nov 18 '22 at 06:04
  • You could perhaps use an ApplicationContextInitialiser to populate the Environment with the properties, or, even better, use OS env vars - in this case setting SQS_QUEUE_INDEXER should do the trick – Miloš Milivojević Nov 18 '22 at 19:09