Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 473
nicolas Avatar asked Jul 16 '16 02:07

nicolas


People also ask

How do you name a SQS queue?

You can name SNS Topics and SQS Queues however you like, as long as it doesn't complain (eg spaces or illegal characters). Don't include 'topic' or 'queue' in the name as they are irrelevant (eg unicorn_invoice is better than unicorn_invoice_queue ). Save this answer.

Is SQS queue name unique?

When you create a new queue, you must specify a queue name unique for your AWS account and region. Amazon SQS assigns each queue you create an identifier called a queue URL that includes the queue name and other Amazon SQS components.

What is Amazonsqsasync?

Amazon SQS is a reliable, highly-scalable hosted queue for storing messages as they travel between applications or microservices. Amazon SQS moves data between distributed application components and helps you decouple these components.

What is QueueMessagingTemplate?

The QueueMessagingTemplate contains many convenience methods to send a message. There are send methods that specify the destination using a QueueMessageChannel object and those that specify the destination using a string which is going to be resolved against the SQS API.


1 Answers

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
like image 184
Miloš Milivojević Avatar answered Sep 30 '22 10:09

Miloš Milivojević