AWS SNS: Add SNS FIFO queues support to NotificationMessagingTemplate: set PublishRequest.messageGroupId and PublishRequest.messageDeduplicationId #777
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.
In
QueueMessageChannel#prepareSendMessageRequest
, there is a special handling ofSqsMessageHeaders.SQS_GROUP_ID_HEADER
andSqsMessageHeaders.SQS_DEDUPLICATION_ID_HEADER
set in theMessage#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:We need to add the same handling and set the values of special headers to
PublishRequest#messageGroupId
andPublishRequest#messageDeduplicationId
.When I do it via pure AWS SDK (
publishRequest.setMessageGroupId
,publishRequest.setMessageDeduplicationId
), the publishing to the same SNS topic is working.