Use @SqsListener annotations to configure the message group ID for the FIFO
I’m using the @SqsListener provided by the Spring Cloud API to consume messages from FIFO queues. I want to use messages based on a specific message group ID. Not sure where to configure this setting.
I tried reading the AWS spring cloud documentation and did some googling but couldn’t find answers or examples.
My note looks like this :
@SqsListener(value = orderQueue, deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
I have the following SQS configuration:
public QueueMessagingTemplate queueMessagingTemplate(AmazonSQSAsync amazonSQSAsync) {
return new QueueMessagingTemplate(amazonSQSAsync);
}
and use the following dependencies:
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws-messaging</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
I’m mostly looking for an answer on how to configure @SqsListener to read messages based on message group IDs.
Solution
I don’t think even the AWS sdk provides a way to consume messages via groupId. groupId is basically just a mechanism for building a cluster of messages in a Fifo queue. Then ensure that messages within the cluster are delivered in the order in which they were sent.