AmazonSQS Inbound Endpoint Example

The AmazonSQS Inbound Endpoint allows you to connect to Amazon and consume messages form an Amazon SQS queue. The messages are then injected into the mediation engine for further processing and mediation.

What you'll build

This scenario demonstrates how the AmazonSQS inbound endpoint works as a message consumer. In this scenario, you should have a connectivity with Amazon AWS account. Please follow the steps mentioned in the Setting up the Amazon Lambda Environment document in order to create an Amazon account and obtain access key id and secret access key.

The Amazon SQS queue will receive messages from a third party system, while the integration runtime will keep listening to the messages from that queue. First you need to create a Queue inside the Simple Queue Service and send a message to the created Queue. The WSO2 AmazonSQS Inbound Endpoint will receive the message and notify. If you are extending this sample scenario, you can perform any kind of mediation using the mediators.

Following diagram shows the overall solution we are going to build. The Simple Queue Service will receive messages from the outside, while the AmazonSQS inbound endpoint will consume messages based on the updates.

AmazonSQS Inbound Endpoint

Configure inbound endpoint using WSO2 Integration Studio

  1. Download WSO2 Integration Studio. Create an Integration Project as below.

Creating a new Integration Project

  1. Right click on Created Integration Project -> New -> Inbound Endpoint -> Create A New Inbound Endpoint -> Inbound Endpoint Creation Type**and select as **custom -> Click Next.

Creating inbound endpoint

  1. Click on Inbound Endpoint in design view and under properties tab, update class name to org.wso2.carbon.inbound.amazonsqs.AmazonSQSPollingConsumer.

  2. Navigate to the source view and update it with the following configuration as required.

<?xml version="1.0" encoding="UTF-8"?>
<inboundEndpoint xmlns="http://ws.apache.org/ns/synapse"   
                 name="AmazonSQS"    
                 onError="requestISO" 
                 sequence="request"    
                 suspend="false" 
                 class="org.wso2.carbon.inbound.amazonsqs.AmazonSQSPollingConsumer">
    <parameters>
        <parameter name="sequential">true</parameter>
        <parameter name="interval">2000</parameter>
        <parameter name="coordination">true</parameter>
        <parameter name="waitTime">19</parameter>
        <parameter name="maxNoOfMessage">10</parameter>
        <parameter name="destination">https://sqs.us-east-2.amazonaws.com/610968236798/eiconnectortestSQS</parameter>
        <parameter name="accessKey">AKIAY4QELOL7GF35XBW5</parameter>
        <parameter name="secretKey">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</parameter>
        <parameter name="attributeNames">attributeName1,contentType</parameter>
        <parameter name="contentType">application/json</parameter>
        <parameter name="class">org.wso2.carbon.inbound.amazonsqs.AmazonSQSPollingConsumer</parameter>
        <parameter name="inbound.behavior">polling</parameter>
    </parameters>
</inboundEndpoint>   
Sequence to process the message

In this example, for simplicity we will just log the message, but in a real world use case, this can be any type of message mediation.

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="request" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <log level="full"/>
</sequence>

Note: To configure the secretKey and accessKey parameter value, please use the Setting up the Amazon Lambda Environment documentation. - secretKey : The secret key used to sign requests. - accessKey : The access key that corresponds to the secret key that you used to sign the request. - destination : URL of the Amazon SQS Queue from which you want to consume messages.

Exporting Integration Logic as a CApp

CApp (Carbon Application) is the deployable artefact on the integration runtime. Let us see how we can export integration logic we developed into a CApp. To export the Solution Project as a CApp, a Composite Application Project needs to be created. Usually, when a solution project is created, this project is automatically created by Integration Studio. If not, you can specifically create it by navigating to File -> New -> Other -> WSO2 -> Distribution -> Composite Application Project.

  1. Right click on Composite Application Project and click on Export Composite Application Project.
    Export as a Carbon Application

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

  3. In the next Create a deployable CAR file screen, select inbound endpoint and sequence artifacts and click Finish. The CApp will get created at the specified location provided in the previous step.

Deployment

  1. Navigate to the connector store and search for AmazonSQS Connector. Click on AmazonSQS Inbound Endpoint and download the .jar file by clicking on Download Inbound Endpoint.

    Note: Copy this .jar file into /dropins folder.

  2. Copy the exported carbon application to the /repository/deployment/server/carbonapps folder.

  3. Start the integration server.

Testing

Please log in to the Amazon Simple Queue Service-> created Queue. Select the Queue and right click-> Send a Message-> enter Message, or you can even use AmazonSQS Connector Example we have implemented before.

Sample Message

{"Message":"Test Amazon SQS Service"}
AmazonSQS Inbound Endpoint will consume message from the Simple Queue Service.

Expected response

You will see following message in the server log file (found at /repository/logs/wso2carbon.log).

[2020-05-22 12:28:03,799]  INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: , MessageID: urn:uuid:CB783799949CD049281590130683750, Direction: request, Payload: {"Message":"Test Amazon SQS Service"}

What's next

Top