spring-attic / spring-cloud-aws

All development has moved to https://github.com/awspring/spring-cloud-aws Integration for Amazon Web Services APIs with Spring
https://awspring.io/
Apache License 2.0
590 stars 373 forks source link

AWS SNS: Add SNS FIFO queues support to NotificationMessagingTemplate: set PublishRequest.messageGroupId and PublishRequest.messageDeduplicationId #777

Closed dmitry-weirdo closed 3 years ago

dmitry-weirdo commented 3 years ago

In QueueMessageChannel#prepareSendMessageRequest, there is a special handling of SqsMessageHeaders.SQS_GROUP_ID_HEADER and SqsMessageHeaders.SQS_DEDUPLICATION_ID_HEADER set in the Message#headers map. This allows us to send a message to a FIFO queue.

However, there is no special handling of these headers in TopicMessageChannel, which leads to this exception, when we try to publish to a FIFO SNS queue:

org.springframework.messaging.MessageDeliveryException: Failed to send message to TopicMessageChannel[TopicMessageChannel@3466aafb]; nested exception is com.amazonaws.services.sns.model.InvalidParameterException: Invalid parameter: The MessageGroupId parameter is required for FIFO topics (Service: AmazonSNS; Status Code: 400; Error Code: InvalidParameter; Request ID: e1895f23-cc29-56e5-b08c-066173822a22; Proxy: null)
    at org.springframework.messaging.support.AbstractMessageChannel.send(AbstractMessageChannel.java:149) ~[spring-messaging-5.3.6.jar:5.3.6]
    at org.springframework.messaging.support.AbstractMessageChannel.send(AbstractMessageChannel.java:125) ~[spring-messaging-5.3.6.jar:5.3.6]

We need to add the same handling and set the values of special headers to PublishRequest#messageGroupId and PublishRequest#messageDeduplicationId.

When I do it via pure AWS SDK (publishRequest.setMessageGroupId, publishRequest.setMessageDeduplicationId), the publishing to the same SNS topic is working.

maciejwalkowiak commented 3 years ago

Implemented in https://github.com/awspring/spring-cloud-aws/pull/130