2

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?

Rich Croft
  • 21
  • 1
  • 2

3 Answers3

13

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);
}
otavaresgabriel
  • 131
  • 1
  • 6
  • 1
    You are right. I've just tested with Spring Cloud AWS 2.2.0.RELEASE and you just have to pass the message-group-id and message-deduplication-id headers, as you said. – Felipe Desiderati Jan 28 '20 at 20:21
0

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.

Louis Alexander
  • 125
  • 2
  • 11
0
private QueueMessageChannel queueMessageOrdensValidadas;

//create template to send
@Autowired
public myClass(final AmazonSQSAsync amazonSQSAsync, 
     @Value("${cloud.aws.fila.ordens-validadas}")
     final String uriOrdensCorrespondentesValidados){
        this.queueMessageOrdensValidadas = new QueueMessageChannel(amazonSQSAsync,uriOrdensCorrespondentesValidados);
        this.uriOrdensCorrespondentesValidados = uriOrdensCorrespondentesValidados;
    }

//to send
queueMessageOrdensValidadas.send(MessageBuilder
     .withPayload(jsonOrdem)
     .setHeader("message-group-id","groupName")
     .build()
);
Fernando
  • 1
  • 1
  • 1
    Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. **Would you kindly [edit] your answer to include additional details for the benefit of the community?** – Jeremy Caney Aug 09 '23 at 02:08