Support Category: Select
Amazon SNS Connector v3.2
The Anypoint Connector for Amazon SNS provides connectivity to the Amazon Simple Notification Service (Amazon SNS) API, enabling you to build distributed web-enabled applications. Mule applications can use the Amazon SNS Connector to easily push real-time notification messages to interested subscribers over multiple delivery protocols.
Prerequisites
To be able to use the Amazon SNS Connector, you must have the following:
-
Access to Amazon Web Services - SNS.
-
AWS Identity and Access Management (IAM) credentials.
-
Anypoint Studio - Enterprise Edition.
This document assumes that you are familiar with Amazon SNS, Mule, Anypoint Connectors, Anypoint Studio, elements in a Mule flow, and global elements.
Compatibility
Amazon SNS connector is compatible with:
Application/Service | Version |
---|---|
Mule Runtime |
3.5.0 and later |
AWS SDK for Java |
1.11.611 |
Java |
1.7.0_x |
Anypoint Studio |
5.4 and later |
Install the Connector
-
In Anypoint Studio, create a Mule project.
-
Click the Anypoint Exchange icon in the Studio task bar.
-
In Anypoint Exchange, click Login and supply your Anypoint Platform username and password.
-
Search for this connector, click the card for the connector, and click Install.
-
Follow the prompts to install the connector.
Update From an Older Version
Each time an updated version of a connector is released, Anypoint Studio displays a popup in the bottom right corner of your system with the following message: Updates Available.
To upgrade to the newer version of the Amazon SNS connector:
-
Click the popup and check for the available updates.
-
Select the Amazon SNS connector version 3.2.3 check box and click Next.
-
Follow the instructions provided by the user interface.
-
Restart Studio when prompted. After restarting, if you have several versions of the connector installed, Mule asks you for the version of the connector to use.
Configure the Connector Global Element
To use the Amazon SNS connector in your Mule application, you must configure a global Amazon SNS element that can be used by all the Amazon SNS connectors in the application.
Studio Visual Editor
-
Click the Global Elements tab at the base of the canvas.
-
On the Global Mule Configuration Elements screen, click Create.
-
In the Choose Global Type wizard, expand Connector Configuration and select Amazon SNS: Configuration and click OK.
-
Configure the parameters according to instructions below.
Parameter Description Name
Enter a name for the configuration to reference it.
Access Key
Alphanumeric text string that uniquely identifies the user who owns the account.
Secret Key
Key that plays the role of a password.
Security Token
Temporary security credentials used to access the AWS resources.
Try AWS Credentials Provider Chain
Checkbox that controls whether temporary credentials should be used.
Region Endpoint
Set the topic region endpoint.
Topic Arn
Topic ARN to test the connectivity.
NoteIn the previous image, the placeholder values refer to a configuration file placed in the src
folder of your project. See Configuring Properties.
You can either enter your credentials into the global configuration properties, or reference a configuration file that contains these values. For simpler maintenance and better re-usability of your project, Mule recommends that you use a configuration file. Keeping these values in a separate file is useful if you must deploy to different environments, such as production, development, and QA, where your access credentials differ. See Deploying to Multiple Environments for instructions on how to manage this.
-
Keep the Pooling Profile and the Reconnection tabs with their default entries.
-
Click Test Connection to confirm that the parameters of your global configuration are accurate, and that Mule is able to successfully connect to your instance of Amazon S3. Read more about this in Testing Connections.
-
Click OK to save the global connector configurations.
XML Editor
Ensure that you have included the Amazon SNS namespaces in your configuration file.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:sns="http://www.mulesoft.org/schema/mule/sns"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/sns
http://www.mulesoft.org/schema/mule/sns/current/mule-sns.xsd">
<!-- Put your flows and configuration elements here -->
</mule>
To configure an Amazon S3 connector in your application, create a global Amazon S3 configuration outside and above your flows, using the following global configuration code:
<sns:config
name="Amazon_SNS__Configuration"
accessKey="${amazon.accesskey}"
secretKey="${amazon.secretkey}"
topicArn="${amazon.sns.topic.arn}"
doc:name="Amazon SNS: Configuration"/>
Use This Connector
Note
|
See the list of operations at Mule Amazon SNS Connector Reference. |
Amazon SNS Connector is an operation-based connector, which means that when you add the connector to your flow, you need to configure a specific operation for the connector to perform. The connector supports the following list of operations:
-
Add Permission
-
Confirm Subscription
-
Create Platform Application
-
Create Platform Endpoint
-
Create Topic
-
Delete Endpoint
-
Delete Platform Application
-
Delete Topic
-
Get Endpoint Attributes
-
Get Platform Application Attributes
-
Get Subscription Attributes
-
Get Topic Attributes
-
List Endpoint By Platform Application
-
List Platform Application
-
List Subscriptions By Topic
-
List Subscriptions
-
List Topics
-
Publish
-
Remove Permission
-
Set Endpoint Attributes
-
Set Platform Application Attributes
-
Set Subscription Attributes
-
Set Topic Attributes
-
Subscribe
-
Unsubscribe
Connector Namespace and Schema
When designing your application in Studio, the act of dragging the connector from the palette onto the Anypoint Studio canvas should automatically populate the XML code with the connector namespace and schema location.
Namespace: http://www.mulesoft.org/schema/mule/sns
Schema Location: http://www.mulesoft.org/schema/mule/sns/current/mule-sns.xsd
Tip
|
If you are manually coding the Mule application in Studio’s XML editor or other text editor, paste these into the header of your Configuration XML, inside the <mule> tag.
|
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sns="http://www.mulesoft.org/schema/mule/sns"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/sns
http://www.mulesoft.org/schema/mule/sns/current/mule-sns.xsd">
<!-- here go your global configuration elements and flows -->
</mule>
Use the Connector in a Mavenized Mule App
If you are coding a Mavenized Mule application, this XML snippet must be included in your pom.xml
file.
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-sns</artifactId>
<version>RELEASE</version>
</dependency>
Mule converts the RELEASE
keyword to the current version.
To specify a version number, view Anypoint Exchange, click Dependency Snippets for the pom.xml
information.
Use Cases and Demos
The following scenarios are common use cases for the connector:
Use Case | Description |
---|---|
Send Amazon SNS Messages to Amazon SQS Queues |
Amazon SNS works closely with Amazon Simple Queue Service (Amazon SQS). By using Amazon SNS and Amazon SQS together, messages can be delivered to applications that require immediate notification of an event, and also persisted in an Amazon SQS queue for other applications to process at a later time. |
Send Amazon SNS Messages to HTTP/HTTPS Endpoints |
You can use Amazon SNS to send notification messages to one or more HTTP or HTTPS endpoints. When you subscribe an endpoint to a topic, you can publish a notification to the topic. When you do this, Amazon SNS sends an HTTP POST request that delivers contents of the notification to the subscribed endpoint. |
Send Messages to Amazon SQS Queue
When you subscribe an Amazon SQS queue to an Amazon SNS topic, you can publish a message to the topic. Amazon SNS then sends an Amazon SQS message to the subscribed queue.
Note
|
You can now subscribe an Amazon SQS queue to an Amazon SNS topic using the AWS Management Console for Amazon SQS, which simplifies the process. Follow the steps mentioned in Subscribe Queue to Amazon SNS Topic. |
-
Create a new Mule project in Anypoint Studio.
-
Add the following properties to the
mule-app.properties
file to hold your Amazon SNS and SQS credentials and place them in the project’ssrc/main/app
directory.amazon.accesskey=<Access Key> amazon.secretkey=<Secret Key> amazon.sns.topic.arn=<SNS Topic ARN> amazon.sns.topic.region=<SNS Topic Region> amazon.sqs.queue.name=<SQS Queue Name> amazon.sqs.queue.region=<SQS Queue Region> amazon.sqs.queue.url=<SQS Queue URL>
-
Drag an HTTP connector onto the canvas and configure the following parameters:
Parameter Value Display Name
HTTP
Connector Configuration
If no HTTP element has been created yet, click the plus sign to add a new HTTP Listener Configuration and click OK (leave the values to its defaults).
Path
/
-
Drag the Amazon SNS Connector next to the HTTP endpoint component.
-
Configure the SNS connector by adding a new Amazon SNS Global Element:
-
Click the plus sign next to the Connector Configuration field.
-
Configure the following fields for the global element:
Parameter Description Value Name
Enter a name for the configuration to reference it.
<Configuration_Name>
Access Key
Alphanumeric text string that uniquely identifies the user who owns the account.
${amazon.accesskey}
Secret Key
Key that plays the role of a password.
${amazon.secretkey}
Region Endpoint
Set the topic region endpoint.
${amazon.sns.topic.region}
Topic Arn
Topic ARN to test the connectivity.
${amazon.sns.topic.arn}
Your configuration should look like this:
The corresponding XML configuration should have these values:
<sns:config name="Amazon_SNS__Configuration" accessKey="${amazon.accesskey}" secretKey="${amazon.secretkey}" doc:name="Amazon SNS: Configuration" testTopicArn="${amazon.sns.topic.arn}" region="${amazon.sns.topic.region}"/>
-
-
Click Test Connection to confirm that Mule can connect with the SNS instance. If the connection is successful, click OK to save the configurations. Otherwise, review or correct any incorrect parameters, then test again.
-
In the properties editor of the Amazon SNS connector, configure the remaining parameters:
Parameter Value Basic Settings
Display Name
Publish message to topic (or any other name you prefer).
Connector Configuration
Amazon_SNS__Configuration (the reference name to the global element you have created).
Operation
Publish
General
Define attributes
Select to define the Publish attributes
Topic Arn
${amazon.sns.topic.arn}
(or any other topic arn).Message
Hello World!
Subject
Testing publish to queue.
-
Check that your XML has these values:
<sns:publish config-ref="Amazon_SNS__Configuration" doc:name="Publish message to topic"> <sns:publish topicArn="${amazon.sns.topic.arn}" message="Hello world!" subject="Testing publish to queue"/> </sns:publish>
-
Add a Logger scope after the Amazon SNS connector to print the data that is being processed by the
Publish
operation in the Mule Console. Configure the Logger:Parameter Value Display Name
Logger (or any other name you prefer)
Message
Message ID:
#[payload]
Level
INFO
-
Add another flow to receive the message published by SNS.
-
Drag a Flow scope onto the canvas.
-
Drag the Amazon SQS Connector next to the HTTP endpoint component and configure it:
-
Click the plus sign next to the Connector Configuration field to add a new Amazon SQS Global Element.
-
Configure the following fields for the global element:
Parameter Description Value
Name
Enter a name for the configuration to reference it.
<Configuration_Name>
Access Key
Alphanumeric text string that uniquely identifies the user who owns the account.
${amazon.accesskey}
Secret Key
Key that plays the role of a password.
${amazon.secretkey}
Queue Name
Set the name of the queue.
${amazon.sqs.queue.name}
Queue URL
Set the queue URL
${amazon.sqs.queue.url}
Region Endpoint
Set the queue reqion
Your configuration should look like this:
The corresponding XML configuration should have these values:
<sqs:config name="Amazon_SQS__Configuration" accessKey="${amazon.accesskey}" secretKey="${amazon.secretkey}" doc:name="Amazon SQS: Configuration" defaultQueueName="${amazon.sqs.queue.name}" region="${amazon.sqs.queue.region}" url="${amazon.sqs.queue.url}"/>
-
-
Click Test Connection to confirm that Mule can connect with the SQS instance. If the connection is successful, click OK to save the configurations. Otherwise, review or correct any incorrect parameters, then test again.
-
In the properties editor of the Amazon SQS connector, configure the remaining parameters:
Parameter Value Basic Settings
Display Name
Amazon SQS (Streaming) (or any other name you prefer).
Connector Configuration
Amazon_SQS__Configuration (the reference name to the global element you have created).
Operation
Receive messages
-
Check that your XML has these values:
<sqs:receive-messages config-ref="Amazon_SQS__Configuration" doc:name="Amazon SQS (Streaming)"/>
-
Add a Logger scope after the Amazon SQS connector to display the data that passed by the
Receive
operation in the Mule Console. .Configure the Logger:Parameter Value Display Name
Display Message (or any other name you prefer)
Message
Received Message :
#[payload]
Level
INFO
-
Save the project.
-
Right-click the project in Package Explorer and click Run As > Mule Application.
-
Open a web browser and check the response after entering the URL
http://localhost:8081/
. The logger displays the published message ID on the browser and the received message on the mule console.
Demo Mule Application XML Code
Paste this code into your XML Editor to quickly load the flow for this example use case into your Mule application.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns:sqs="http://www.mulesoft.org/schema/mule/sqs"
xmlns:json="http://www.mulesoft.org/schema/mule/json"
xmlns:sns="http://www.mulesoft.org/schema/mule/sns"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/json
http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/sqs
http://www.mulesoft.org/schema/mule/sqs/current/mule-sqs.xsd
http://www.mulesoft.org/schema/mule/sns
http://www.mulesoft.org/schema/mule/sns/current/mule-sns.xsd
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/tracking
http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<http:listener-config
name="HTTP_Listener_Configuration"
host="0.0.0.0"
port="8081"
doc:name="HTTP Listener Configuration"/>
<sqs:config
name="Amazon_SQS__Configuration"
accessKey="${amazon.accesskey}"
secretKey="${amazon.secretkey}"
doc:name="Amazon SQS: Configuration"
defaultQueueName="${amazon.sqs.queue.name}"
region="${amazon.sqs.queue.region}"
url="${amazon.sqs.queue.url}"/>
<sns:config
name="Amazon_SNS__Configuration"
accessKey="${amazon.accesskey}"
secretKey="${amazon.secretkey}"
doc:name="Amazon SNS: Configuration"
testTopicArn="${amazon.sns.topic.arn}"
region="${amazon.sns.topic.region}"/>
<flow name="publish_message_to_topic" >
<http:listener
config-ref="HTTP_Listener_Configuration"
path="/"
doc:name="HTTP"/>
<sns:publish config-ref="Amazon_SNS__Configuration" doc:name="Publish message to topic">
<sns:publish
topicArn="${amazon.sns.topic.arn}"
message="Hello world!"
subject="Testing publish to queue"/>
</sns:publish>
<logger message="Message ID: #[payload]" level="INFO" doc:name="Logger"/>
</flow>
<flow name="receive_message_from_queue">
<sqs:receive-messages
config-ref="Amazon_SQS__Configuration"
doc:name="Amazon SQS (Streaming)"/>
<logger message="Received Message : #[payload]" level="INFO"
doc:name="Display Message" />
<logger
message="Message with handle : #[header:inbound:sqs.message.receipt.handle]"
level="INFO"
doc:name="Display Message Handle"/>
</flow>
</mule>
Download Demo Applications
You can download a fully functional example from Mule Amazon SNS Connector on github.io.