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
The starter automatically configures and registers a `SnsTemplate` bean providing higher level abstractions for sending SNS notifications.
22
+
`SnsTemplate` implements Spring Messaging abstractions making it easy to combine with other messaging technologies compatible with Spring Messaging.
23
+
24
+
It supports sending notifications with payload of type:
12
25
13
-
==== Sending a message
14
-
The `NotificationMessagingTemplate` contains two convenience methods to send a notification. The first one specifies the
15
-
destination using a `String` which is going to be resolved against the SNS API. The second one takes no destination
16
-
argument and uses the default destination. All the usual send methods that are available on the `MessageSendingOperations`
17
-
are implemented but are less convenient to send notifications because the subject must be passed as header.
26
+
* `String` - using `org.springframework.messaging.converter.StringMessageConverter`
27
+
* `Object` - which gets serialized to JSON using `org.springframework.messaging.converter.MappingJackson2MessageConverter` and Jackson's `com.fasterxml.jackson.databind.ObjectMapper` autoconfigured by Spring Boot.
18
28
19
-
[NOTE]
20
-
====
21
-
Currently only `String` payloads can be sent using the `NotificationMessagingTemplate` as this is the expected
22
-
type by the SNS API.
23
-
====
29
+
Additionally, it exposes handful of methods supporting `org.springframework.messaging.Message`.
This example constructs a new `NotificationMessagingTemplate` by passing an `AmazonSNS` client as argument. In the `send`
47
-
method the convenience `sendNotification` method is used to send a `message` with `subject` to an SNS topic. The
48
-
destination in the `sendNotification` method is a string value that must match the topic name defined on AWS. This value
49
-
is resolved at runtime by the Amazon SNS client. Optionally a `ResourceIdResolver` implementation can be passed to the
50
-
`NotificationMessagingTemplate` constructor to resolve resources by logical name when running inside a CloudFormation stack.
51
-
(See <<Managing cloud environments>> for more information about resource name resolution.)
59
+
If autoconfigured converters do not meet your needs, you can provide a custom `SnsTemplate` bean with a message converter of your choice.
52
60
53
-
It is recommended to use the XML messaging namespace to create `NotificationMessagingTemplate` as it will automatically
54
-
configure the SNS client to setup the default converter.
61
+
When sending SNS notification, it is required to provide a topic ARN. Spring Cloud AWS simplifies it and allows providing a topic name instead, under a condition that topic with that name has already been created.
62
+
Otherwise, Spring Cloud AWS will make an attempt to create topic with this name with a first call.
The behavior of resolving topic ARN by a topic name can be altered by providing a custom bean of type `io.awspring.cloud.sns.core.TopicArnResolver`.
65
+
66
+
==== SNS Operations
60
67
61
-
FIFO SNS Topics have additional required and optional request parameters. For example MessageGroupId is a required
62
-
parameter for a FIFO topic. These parameters can be set by specifying them in the headers map.
63
-
Spring Cloud AWS extracts the keys and sets the parameters on the underlying SNS SendMessage request.
68
+
Because of Spring Messaging compatibility, `SnsTemplate` exposes many methods that you may not need if you don't need Spring Messaging abstractions.
69
+
In such case, we recommend using `SnsOperations` - an interface implemented by `SnsTemplate`, that exposes a convenient method for sending SNS notification, including support for FIFO topics.
64
70
65
-
To specify message attributes on the SNS SendMessage request, additional headers can be added to the header map.
To have access to all lower level SNS operations, we recommend using `SnsClient` from AWS SDK. `SnsClient` bean is autoconfigured by `SnsAutoConfiguration`.
79
97
80
-
public class SnsNotificationSender {
98
+
If autoconfigured `SnsClient` bean configuration does not meet your needs, it can be replaced by creating a custom bean of type `SnsClient`.
81
99
82
-
private final NotificationMessagingTemplate notificationMessagingTemplate;
Since 2.4.0 verification has been introduced for Notification request and is turned on by default. Verification is using same region as SNSClient is.
110
-
To turn off verification simply set property 'cloud.aws.sns.verification=false'.
111
-
With Localstack verification won't work, so you have to set property to 'false' if you want `@NotificationMessageMapping` to work properly.
112
-
For more information about SNS verification https://docs.awspring.io/spring-cloud-aws/docs/2.3.3/reference/html/index.html [here].
113
-
====
126
+
HTTP endpoints are based on Spring MVC controllers. Spring Cloud AWS added some custom argument resolvers to extract the message and subject out of the notification requests.
114
127
115
-
HTTP endpoints are based on Spring MVC controllers. Spring Cloud AWS added some custom argument resolvers to extract
116
-
the message and subject out of the notification requests.
0 commit comments