Skip to content

Missing SNS attributes when sending a message via SnsTemplate and receiving via @SqsListener #1111

@mt-ocado

Description

@mt-ocado

Type: Bug

Component: SNS, SQS

Description
Reference documentation mentions that when we receive SNS messages through the @SqsListener, the message includes all attributes of the SnsNotification. However, the attributes are not passed to message headers.

Sample
Having an SQS queue that is subscribed to SNS topic (raw message delivery is disabled), when sending to SNS via snsTemplate as following

 snsTemplate.convertAndSend(topicName, pojo, Map.of("my-attribute", "attribute-value"));

and receiving the message via @SqsListener as following

 @SqsListener("${queueName}")
 public void processGreetingsEvent(Message<?> message){
     System.out.println(message.getHeaders().get("my-attribute"))
 }

then null is printed instead of "attribute-value".

The same effect is seen when receiving as following

@SqsListener("${queue.name}")
public void processGreetingsEvent(@SnsNotificationMessage Pojo pojo, @Headers Map<String, Object> headers) {
    headers.get("my-attribute"))
}

Am I missing something? Is there a way I can access the attributes (I did not find direct information in the documentation).

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: snsSNS integration related issuecomponent: sqsSQS integration related issuetype: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions