2
votes

I'm using spring-cloud-aws to send a message to SQS FIFO queue.

It's failing with

The request must contain the parameter MessageGroupId

There doesn't seem to be anywhere on the QueueMessagingTemplate in spring-cloud-aws-messaging that allows me to set this mandatory MessageGroupId.

Is there currently a way of writing to a SQS FIFO queue in this manor or would I have to revert to directly using amazons API?

2

2 Answers

7
votes

Spring Cloud AWS support FIFO queues since 2017, in accordance with: Add Support for FIFO SQS Queues #252

You just need to add the two required params(messageGroupId and messageDeduplicationId) like example below:

public void send(String topicName, Object message, String messageGroupId, String messageDeduplicationId) throws MessagingException {
    Map<String, Object> headers = new HashMap<>();
    headers.put("message-group-id", messageGroupId);
    headers.put("message-deduplication-id", messageDeduplicationId);
    messagingTemplate.convertAndSend(topicName, message, headers);
}
0
votes

I dont believe that FIFO support is possible with versions 1.1.x of spring-cloud-aws due to how the QueueMessagingTemplate uses a QueueMessagingChannel that does not support configuring the SendMessageRequest in this way.

Examine https://github.com/spring-cloud/spring-cloud-aws/blob/master/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/core/QueueMessageChannel.java#L78 for details.

I have opened https://github.com/spring-cloud/spring-cloud-aws/issues/246 for this reason, though have no idea if support will be added.

It also does not appear that I can use a custom QueueMessageTemplate; this would be a reasonable workaround if I could.