You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/main/asciidoc/sqs.adoc
+28Lines changed: 28 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -632,6 +632,34 @@ Any number of `@SqsListener` annotations can be used in a bean class, and each a
632
632
633
633
NOTE: Queues declared in the same annotation will share the container, though each will have separate throughput and acknowledgement controls.
634
634
635
+
===== Handling Different Payload In The Same Listener
636
+
637
+
It's possible to handle different payloads in the same listener by annotating handler methods with the `@SqsHandler` annotation.
638
+
Here's a sample:
639
+
[source, java]
640
+
----
641
+
@SqsListener("myQueue")
642
+
public class MyListener {
643
+
644
+
@SqsHandler
645
+
public void handle(String message) {
646
+
System.out.println(message);
647
+
}
648
+
649
+
@SqsHandler
650
+
public void handle(MyPojo pojo) {
651
+
System.out.println(pojo);
652
+
}
653
+
654
+
@SqsHandler(isDefault = true)
655
+
public void handle(Object message) {
656
+
System.out.println(message);
657
+
}
658
+
}
659
+
----
660
+
661
+
The `isDefault = true` parameter designates a method as the fallback handler for messages that don't match any other handler's parameter type.
662
+
635
663
===== SNS Messages
636
664
637
665
Since 3.1.1, when receiving SNS messages through the `@SqsListener`, the message includes all attributes of the `SnsNotification`. To only receive need the `Message` part of the payload, you can utilize the `@SnsNotificationMessage` annotation.
Copy file name to clipboardExpand all lines: spring-cloud-aws-sqs/src/main/java/io/awspring/cloud/sqs/annotation/AbstractListenerAnnotationBeanPostProcessor.java
Copy file name to clipboardExpand all lines: spring-cloud-aws-sqs/src/main/java/io/awspring/cloud/sqs/annotation/SqsListenerAnnotationBeanPostProcessor.java
0 commit comments