Amazon Simple Queue Service (Amazon SQS) offers a secure, durable, and available hosted queue that lets you integrate and decouple distributed software systems and components. Amazon SQS offers common constructs such as dead-letter queues and cost allocation tags. It provides a generic web services API and it can be accessed by any programming language that the AWS SDK supports.
Amazon SQS supports both standard and FIFO queues.
Sign-up for an AWS account and setup the SQS queue(s). You must set up at least one queue which will act as the default for messages from PubNub.
Sign-up for a PubNub account, if you don't have one already.
Import the Integration Block into your PubNub account. You can choose to add this to an existing application or create a new one.
Configure the Integration Block module code, connecting it to your AWS account:
Create a Secret in PubNub Vault, named AWS_ACCESS_KEY_ID, with value equal to your AWS Access Key ID for this service.
Create a Secret in PubNub Vault, named AWS_SECRET_KEY, with value equal to your AWS Secret Key for this service.
Create a Secret in PubNub Vault, named AWS_REGION, with value equal to your AWS Region for the target queue .
Create a Secret in PubNub Vault, named AWS_ACCOUNT_NUMBER, with value equal to your AWS Account ID for this service.
Create a Secret in your PubNub Vault, named AWS_DEFAULT_QUEUE_NAME, with the name of the AWS queue that you created in step 1.
Start the Integration Block module.
Try a test message (you can click on Publish
to do this).
After importing the Integration Block to your account, a new function called “Amazon SQS v2” will be setup to listen to a specific PubNub channel (CHANNEL-to-send-to-SQS), but you can configure it to listen to all channels or a subset, using wildcards, e.g. chat.*.
Whenever your app publishes a message on the channel that you specified, the function will write the message body to the AWS SQS queue that you specified in the vault as AWS_DEFAULT_QUEUE_NAME.
You can also overwrite the default queue name specified in the function code by publishing messages with additional metadata that specifies a different queue name to use.
The following example describes how to set the metadata so that the message published is sent to a queue named “my_dyanamic_queue”:
{ "functions": { "aws-sqs-v2": { "input": { "TARGET_QUEUE_NAME": "my_dyanamic_queue" } } } }
Your metadata should include a JSON object that matches this format, with whatever value you need as the value for the TARGET_QUEUE_NAME field. Examples of how to publish messages with metadata can be found in the Publish documentation.
Need help? Contact PubNub Support.
Copyright (c) 2018 PubNub
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.