Java – configure Amazon SQS queue name in spring boot

I am using Amazon SQS & spring boot (spring cloud AWS messaging) I have configured a message listener to receive messages from the queue using the annotation @ sqslistener

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

This is a very simple method, but I can't find a way to load queue names from the configuration file because I have different environments Any thoughts on this?

Solution

What version of spring cloud AWS messaging do you use? Version 1.1 should allow you to use placeholders as queue names, such as

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

Then, in application env In the properties file, you can add different values For example, in application-dev.properties:

sqs.queue.indexer=devIndexerQueue

In application production Properties

sqs.queue.indexer=indexerQueue
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>