Sending AWS SNS Messages
The AWS SNS connector allows you to send messages to an AWS SNS topic.
Sending messages
Before you start, you need to have an AWS account and an SNS topic created. To send messages to an SNS topic, you need to create a method that produces messages to the topic.
Then, your application can send Message<String>
to the prices channel.
It can use String
payloads as in the following snippet:
Or, you can send Message<Double>
, which affords the opportunity to
explicitly specify metadata on the outgoing message:
Sending messages in batch
You can configure the outbound channel to send messages in batch of maximum 10 messages (AWS SNS limitation).
You can customize the size of batches, 10
being the default batch size, and the delay to wait for new messages to be added to the batch, 3000ms being the default delay:
Serialization
When sending a Message<T>
, the connector converts the message into a AWS SNS Message.
How the message is converted depends on the payload type:
- If the payload is of type
PublishRequest
it is sent as is. - If the payload is of type
PublishRequest.Builder
, the topic url is set and sent. - If the payload is of primitive types the payload is converted to String and the message attribute
_classname
is set to the class name of the payload. - If the payload is of any other object type, the payload is serialized (using the
JsonMapping
implementation discovered) and the message attribute_classname
is set to the class name of the payload.
If the message payload cannot be serialized to JSON, the message is nacked.
Outbound Metadata
When sending Messages
, you can add an instance of SnsOutboundMetadata
to influence how the message is handled by AWS SNS. For example, you can configure the routing key, timestamp and headers:
Acknowledgement
By default, the Reactive Messaging Message
is acknowledged when the
send message request is successful. If the message is not sent successfully, the message is nacked.
Configuration Reference
Attribute (alias) | Description | Type | Mandatory | Default |
---|---|---|---|---|
batch | When set, sends messages in batches of maximum 10 messages | boolean | false | false |
batch-delay | In batch send mode, the maximum delay in milliseconds to wait for messages to be included in the batch. Defaults to 3000 ms | int | false | 3000 |
batch-size | In batch send mode, the maximum number of messages to include in batch, currently SNS maximum is 10 messages | int | false | 10 |
credentials-provider | The credential provider to be used in the client, defaults to AWS default provider chain | string | false | |
email.subject | When set, sends messages with the specified subject | string | false | |
endpoint-override | The endpoint override | string | false | |
group.id | When set, sends messages with the specified group id | string | false | |
health-enabled | Whether health reporting is enabled (default) or disabled | boolean | false | true |
message-structure | Set to json if you want to send a different message for each protocol. | string | false | |
region | The name of the SNS region, defaults to AWS region resolver | string | false | |
sms.phoneNumber | When set, sends messages to the specified phone number. Not supported in combination with batching. | string | false | |
topic | The name of the SNS topic, defaults to channel name if not provided | string | false | |
topic.arn | The arn of the SNS topic | string | false |