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 Amazon SQS. Send a JSON message to the created queue. Both operations are exposed via an API. The API with the context /sqs has two resources: /createQueue - Once invoked, it will create a queue in Amazon SQS with the specified name /sendMessage - The incoming JSON message will be sent to the specified queue The following diagram shows the overall solution. The user creates a queue, sends a JSON message to the queue. To invoke each operation, the user uses the same API. If you do not want to configure this yourself, you can simply get the project and run it. Set up the integration project¶ Follow the steps in the Creating an Integration Project guide to set up the Integration Project. Add integration logic¶ Follow the Creating a REST API guide to create a REST API. Specify the API name as SQSAPI and the API context as /sqs. Configure the API¶ First, create the /createQueue resource. For guidance, refer to the Add new API resources guide. Use the following details when configuring the resource. URI Template: /createQueue HTTP Method: POST Set up the Create Queue operation. Select the createQueue resource. Click on the + icon on the canvas to open the Mediator Palette and search for the SQS connector. Search for the SQS connector and download the connector if you have not done so already. After downloading, you can see the Amazon SQS connector in the mediator palette. Click on the Create Queue operation under the SQS connector. Then, click on Add new connection to create a new SQS Connection. Following values can be provided when connecting to the SQS service. Connection Name - Unique name to identify the connection by. Access Key ID - Access key associated with your Amazon user account. Secret Access Key - Secret Access key associated with your Amazon user account. Region - Region that is used to select a regional endpoint to make requests. Click on Add to create the connection. You can see the created connection in the Connection drop-down list. Select the created connection from the list. Configure the createQueue operation by providing the following expressions for the properties. These expressions will retrieve the respective values from the JSON request payload. Queue Name: payload.queueName To store the response of the operation in the message body, select Overwrite Message Body in the Output Section. This will allow you to send the response back to the user as a response of the API invocation. Send a response to the user. Add Respond mediator after the above operation. Create the next API resource (which is /sendMessage) by doing same steps as create /createQueue. This API resource will send the incoming JSON message to the specified queue. Use the following details when configuring the resource. URI Template: /sendMessage HTTP Method: POST Setup the Send Message operation. Provide expressions for the following properties. These expressions will retrieve the respective values from the JSON request payload. Queue URL: payload.queueUrl Message Body: payload.message Select Overwrite Message Body as true to overwrite the response body with the response from the operation. Add a Respond mediator after the above operation. Get the project¶ You can download the ZIP file and extract the contents to get the project code. Tip You may need to update the value of the access key and make other such changes before deploying and running this project. Deployment¶ To deploy and run the project, refer to the Build and Run guide. Testing¶ Invoke the API resources as shown below using the MI VSCode Extension. Creating a queue in Amazon SQS¶ Sample request { "ResponseMetadata": { "RequestId": "c253d4b6-e9b3-58e8-96f7-b4574a35540b" }, "CreateQueueResult": { "QueueUrl": "https://sqs.us-east-2.amazonaws.com/446449776830/wso2-test-queue" }, "success": true } Expected Response: You will receive a response like below containing the details of the queue created. { "success": true, "result": { "queueUrl": "https://sqs.us-east-2.amazonaws.com/123456789012/wso2-test-queue" } } Please navigate to Amazon AWS SQS console and see if a queue called wso2-test-queue is created. Send a message to the Amazon SQS queue¶ Sample request { "queueUrl": "https://sqs.us-east-2.amazonaws.com/123456789012/wso2-test-queue", "message": { "orderId": "12345", "product": "WSO2 Integration Suite", "quantity": 2, "customer": { "name": "John Doe", "email": "[email protected]" } } } Expected Response: You will receive a response like below containing the details of the message sent. { "ResponseMetadata": { "RequestId": "6c641e9d-a530-5a04-ac7f-7e7c06e1f8d8" }, "SendMessageResult": { "MessageId": "bcc28e2d-960e-4faa-a611-010418e81809", "MD5OfMessageBody": "ec4b6ea3aed2a32ecb5d30dcfd65df4d" }, "success": true } Navigate to the AWS SQS console and click on the queue wso2-test-queue. You will note that a message has been sent to the queue and you can view the message content by polling the queue. What's next¶ To customize this example for your own scenario, see Amazon SQS Connector Configuration documentation.