AmazonSQS Connector Example

The WSO2 Amazon SQS connector allows you to access the exposed Amazon SQS API from an integration sequence.

What you'll build

This example explains how to use Amazon SQS Connector to create a queue in the Amazon SQS, send a message to the queue, forward it to Simple Stock Quote Service Backend and send the response to the user.

It has a single HTTP API resource, which is sendToQueue.


If you do not want to configure this yourself, you can simply get the project and run it.

Setting up the environment

  1. Please follow the steps mentioned in the Setting up the Amazon S3 Environment document in order to create a Amazon account and obtain access key id and secret access key. Keep them saved to be used in the next steps.

  2. In this example we will be using XPath 2.0 which needs to be enabled in the product as shown below before starting the integration service.

    If you are using the Micro Integrator of EI 7 or APIM 4.0.0, you need to enable this property by adding the following to the PRODUCT-HOME/conf/deployment.toml file. You can further refer to the Product Configurations.


    If you are using EI 6, you can enable this property by uncommenting synapse.xpath.dom.failover.enabled=true property in PRODUCT-HOME/conf/ file.

  3. In this example we use the SimpleStockQuote service backend. Therefore, the SimpleStockQuote service needs to be started.

Configure the connector in WSO2 Integration Studio

Follow these steps to set up the Integration Project and the Connector Exporter Project.

  1. Open WSO2 Integration Studio and create an Integration Project. Creating a new Integration Project

  2. Right-click the project that you created and click on Add or Remove Connector -> Add Connector. You will get directed to the WSO2 Connector Store.

  3. Search for the specific connector required for your integration scenario and download it to the workspace.
    Search Connector in the Connector Store

  4. Click Finish, and your Integration Project is ready. The downloaded connector is displayed on the side palette with its operations.

  5. You can drag and drop the operations to the design canvas and build your integration logic. Drag connector operations

  6. First let's create the following sequences, which are buildMessage, createQueue, sendMessage and ReceiveAndForwardMessage. Right click on the created Integration Project and select, -> New -> Sequence to create the Sequence. Adding a Sequence

  7. Provide the Sequence name as buildMessage. You can go to the source view of the XML configuration file of the API and copy the following configuration. In this sequence we are taking the user's input companyName and we build the message using a Payload Factory Mediator.

      <?xml version="1.0" encoding="UTF-8"?>
      <sequence name="buildMessage" trace="disable" xmlns="">
          <property expression="json-eval($.companyName)" name="companyName" scope="default" type="STRING"/>
          <payloadFactory media-type="xml">
                  <m0:getQuote xmlns:m0="http://services.samples">
                  <arg evaluator="xml" expression="get-property('companyName')"/>
          <header name="Action" scope="default" value="urn:getQuote"/>
              <source clone="true" type="body"/>
              <target property="target_property" type="property"/>

  8. Create the createQueue sequence as shown below. In this sequence, we create a queue in the Amazon SQS instance.

      <?xml version="1.0" encoding="UTF-8"?>
      <sequence name="createQueue" trace="disable" xmlns="">
          <property expression="json-eval($.CreateQueueResponse.CreateQueueResult.QueueUrl)" name="queueURL" scope="default" type="STRING"/>
          <log level="custom">
              <property expression="$ctx:queueURL" name="queueURL"/>
          <property expression="fn:substring($ctx:queueURL,39,12)" name="queueId" scope="default" type="STRING" xmlns:fn=""/>
          <log level="custom">
              <property expression="$ctx:queueId" name="queueId"/>

  9. Create sendMessage sequence as shown below. In this sequence, we send the message that we built in step 1 to the Amazon SQS Queue.

      <?xml version="1.0" encoding="UTF-8"?>
      <sequence name="sendMessage" trace="disable" xmlns="">

  10. Create the ReceiveAndForwardMessage sequence as shown below. In this sequence, we will receive the message from the Amazon SQS queue and forward it into the StockQuote Endpoint.

      <?xml version="1.0" encoding="UTF-8"?>
      <sequence name="ReceiveAndForwardMessage" trace="disable" xmlns="">
          <property expression="json-eval($.ReceiveMessageResponse.ReceiveMessageResult.Message.Body)" name="messageBody" scope="default" type="STRING"/>
          <payloadFactory media-type="xml">
                  <soapenv:Envelope xmlns:soapenv="">
                  <arg evaluator="xml" expression="$ctx:messageBody"/>
          <header name="Action" scope="default" value="urn:getQuote"/>
              <endpoint key="SimpleStockQuote"/>

  11. Now right click on the created Integration Project and select New -> Rest API to create the REST API.

  12. Provide the API name as SQSAPI and the API context as /sqs. You can go to the source view of the XML configuration file of the API and copy the following configuration.

      <?xml version="1.0" encoding="UTF-8"?>
      <api context="/sqs" name="SQSAPI" xmlns="">
          <resource methods="POST" uri-template="/sendToQueue">
                  <property expression="json-eval($.queueName)" name="queueName" scope="default" type="STRING"/>
                  <sequence key="buildMessage"/>
                  <sequence key="createQueue"/>
                  <sequence key="sendMessage"/>
                  <sequence key="ReceiveAndForwardMessage"/>

Exporting Integration Logic as a CApp

CApp (Carbon Application) is the deployable artifact on the integration runtime. Let us see how we can export integration logic we developed into a CApp along with the connector.

Creating Connector Exporter Project

To bundle a Connector into a CApp, a Connector Exporter Project is required.

  1. Navigate to File -> New -> Other -> WSO2 -> Extensions -> Project Types -> Connector Exporter Project.
    Add Connector Exporter Project

  2. Enter a name for the Connector Exporter Project.

  3. In the next screen select, Specify the parent from workspace and select the specific Integration Project you created from the dropdown. Naming Connector Exporter Project

  4. Now you need to add the Connector to Connector Exporter Project that you just created. Right-click the Connector Exporter Project and select, New -> Add Remove Connectors -> Add Connector -> Add from Workspace -> Connector

  5. Once you are directed to the workspace, it displays all the connectors that exist in the workspace. You can select the relevant connector and click Ok. Selecting Connector from Workspace

Creating a Composite Application Project

To export the Integration Project as a CApp, a Composite Application Project needs to be created. Usually, when an Integration project is created, this project can be created as part of that project by Integration Studio. If not, you can specifically create it by navigating to File -> New -> Other -> WSO2 -> Distribution -> Composite Application Project.

Exporting the Composite Application Project

  1. Right-click the Composite Application Project and click Export Composite Application Project.

Export as a Carbon Application

  1. Select an Export Destination where you want to save the .car file.

  2. In the next Create a deployable CAR file screen, select both the created Integration Project and the Connector Exporter Project to save and click Finish. The CApp is created at the specified location provided at the previous step. Create a deployable CAR file

Get the project

You can download the ZIP file and extract the contents to get the project code.

Download ZIP


You may need to update the value of the access key and make other such changes before deploying and running this project.


Follow these steps to deploy the exported CApp in the integration runtime.

Deploying on Micro Integrator

You can copy the composite application to the <PRODUCT-HOME>/repository/deployment/server/carbonapps folder and start the server. Micro Integrator will be started and the composite application will be deployed.

You can further refer the application deployed through the CLI tool. See the instructions on managing integrations from the CLI.

Click here for instructions on deploying on WSO2 Enterprise Integrator 6
  1. You can copy the composite application to the <PRODUCT-HOME>/repository/deployment/server/carbonapps folder and start the server.

  2. WSO2 EI server starts and you can login to the Management Console https://localhost:9443/carbon/ URL. Provide login credentials. The default credentials will be admin/admin.

  3. You can see that the API is deployed under the API section.


  1. Create a file called data.json with the following payload.
  2. Invoke the API as shown below using the curl command. Curl Application can be downloaded from here.
    curl -H "Content-Type: application/json" --request POST --data @body.json http://localhost:8290/sqs/sendToQueue

Expected Response:

You should get the following response with the 'sys_id' and keep it saved.

<ns:getQuoteResponse xmlns:ns="http://services.samples">
    <ns:return xmlns:ax21="http://services.samples/xsd" xmlns:xsi="" xsi:type="ax21:GetQuoteResponse">
        <ax21:lastTradeTimestamp>Wed Apr 08 10:38:56 IST 2020</ax21:lastTradeTimestamp>
        <ax21:name>WSO2 Company</ax21:name>

What's Next