I have a spring boot application where i am using SQS for some async tasks. I want to configure 2 types of instances in this application:
- Server instance: responsible for pushing message to SQS queue.
- Worker instance: responsible for listening messages from SQS queue.
For listening messages I am using @SqsListener
annotation like this:
@SqsListener("queue_name")
public void loadMessagesFromQueue(Object message) {
log.info("inside loadMessagesFromQueue");
log.info("Queue Messages: " + message);
}
The ask here is that i want to disable this SqsListener
on the server instance and just want it to run on the worker instance. How do I achieve this? I have tried searching if there is a way to disable it using some config variable but didn't find anything
I have figured out a way to do it. I have created 2 separate YAML files for server and worker instances and configured a variable
cloud.aws.sqs.autoStart
in both the YAML files. I have kept the value of autoStart as True on the worker instance and as False on the server instance.While creating the
SimpleMessageListenerContainerFactory
I am using this variable like this: