Repository navigation
Spring Integration SNS
An outbound adapter is used to send messages to a SNS topic.
Configuration via XML:
<int:channel id="incoming" />
<int-sns:outbound-channel-adapter id="outbound-adapter"
topic-name="top-picks"
aws-credentials-provider="bean-ref"
channel="incoming" />
- topic-name: Name of the SNS topic to post messages
-
aws-credentials-provider: Reference to a bean which implements the
com.amazonaws.auth.AWSCredentialsProviderinterface -
channel: The message channel to which the application will push a
Message
This is same as the outbound adapter, you need to add the reply-channel attribute.
An inbound adapter can be used to receive messages from a SNS topic. Behind the scenes, a HTTP endpoint is registered for an inbound adapter; this implies that the inbound adapter can only be used in a web context.
Configuration via XML:
<int-sns:inbound-channel-adapter id="inbound-adapter"
topic-name="top-picks"
aws-credentials-provider="bean-ref"
channel="out">
<int-sns:endpoint base-uri="http://www.example.com/context"/>
</int-sns:inbound-channel-adapter>
- endpoint: specifies the base URL of the web application. This will be used to subscribe a HTTP endpoint to the SNS topic
If your application sends and receives messages from the same SNS topic, you should use a channel. Incoming messages are received over a HTTP endpoint, so this only works in a web context.
Configuration via XML:
<int-sns:publish-subscribe-channel id="channel"
topic-name="top-picks"
aws-credentials-provider="bean-ref">
<int-sns:endpoint base-uri="http://www.example.com/context"/>
</int-sns:publish-subscribe-channel>
- The
publish-subscribe-channelbroadcasts incoming messages to all subscribers.
The inbound adapter and the channel transparently create an HTTP listener which receives and processes SNS subscription requests and notifications. The endpoint element has an optional request-path attribute; if it is not specified, the adapter will use the adapter id attribute, for example, in the preceding XML configuration, the endpoint URL will be http://www.example.com/context/channel.do. For this to work correctly, you need to make sure that the *.do url-pattern is mapped to the Spring DispatcherServlet servlet. If your application uses a different url-pattern, you will need to specify the request-path attribute.
It is possible to add SNS subscriptions to the int-sns:publish-subscribe-channel. Subscriptions can be HTTP endpoints or SQS queues.
<int-sns:inbound-channel-adapter id="inbound-adapter"
topic-name="top-picks"
aws-credentials-provider="bean-ref"
channel="out">
<int-sns:endpoint base-uri="http://www.example.com/context"/>
<int-sns:subscriptions>
<int-sns:http base-uri="http://www.example.com" />
<int-sns:http base-uri="http://www.another-example.com" request-path="/notifications" />
<int-sns:sqs queue-id="sqsInbound"/>
</int-sns:subscriptions>
</int-sns:inbound-channel-adapter>
<int-sqs:inbound-channel-adapter id="sqsInbound"
queue-name="sqsInboundQueue"
aws-credentials-provider="bean-ref"
channel="logSqsInbound" />
<int:channel id="logSqsInbound" />
The HTTP endpoints can point to other web applications as well. The HTTP handlers at all endpoints must be capable of handling Amazon SNS subscription requests and notifications.
The int-sns:sqs sub-element also accepts a queue-arn attribute. You can use this if you are publishing to a third-party queue. Note that the library will not automatically handle SQS permissions in this case, you will have to give the SNS topic permissions to publish to the SQS queue.
If you are not using Spring STS (or its Eclipse plugin), you will need to refer to the GitHub raw path to resolve the XML namespace.
namespace : http://www.springframework.org/schema/integration/sns