CDNShark Documentation

SharkMQ

← Back to Documentation

Use Your Existing Amazon SQS Code

SharkMQ speaks the Amazon SQS API. Keep your code and your AWS SDK, and change three settings:

SettingValue
Endpointhttps://sqs.cdnshark.com
Access key id / secretFrom a SharkMQ user (see Users, Access Keys and Permissions)
RegionAny value, for example us-east-1

Use an AWS SDK from 2023 or later; older SDKs use a request format SharkMQ does not accept for SQS yet.

Python (boto3)

import boto3, os
sqs = boto3.client("sqs", endpoint_url="https://sqs.cdnshark.com", region_name="us-east-1",
                   aws_access_key_id=os.environ["SHARKMQ_KEY"],
                   aws_secret_access_key=os.environ["SHARKMQ_SECRET"])
url = sqs.create_queue(QueueName="orders")["QueueUrl"]
sqs.send_message(QueueUrl=url, MessageBody="order 42")
resp = sqs.receive_message(QueueUrl=url, WaitTimeSeconds=20, MaxNumberOfMessages=10)
for m in resp.get("Messages", []):
    print(m["Body"])
    sqs.delete_message(QueueUrl=url, ReceiptHandle=m["ReceiptHandle"])

Node.js (AWS SDK v3)

import { SQSClient, SendMessageCommand } from "@aws-sdk/client-sqs";
const sqs = new SQSClient({ endpoint: "https://sqs.cdnshark.com", region: "us-east-1",
  credentials: { accessKeyId: process.env.SHARKMQ_KEY, secretAccessKey: process.env.SHARKMQ_SECRET } });
await sqs.send(new SendMessageCommand({ QueueUrl: process.env.QUEUE_URL, MessageBody: "order 42" }));

PHP (AWS SDK for PHP)

$sqs = new Aws\Sqs\SqsClient(['endpoint' => 'https://sqs.cdnshark.com', 'region' => 'us-east-1',
    'version' => 'latest', 'credentials' => ['key' => getenv('SHARKMQ_KEY'), 'secret' => getenv('SHARKMQ_SECRET')]]);
$sqs->sendMessage(['QueueUrl' => getenv('QUEUE_URL'), 'MessageBody' => 'order 42']);

Queue URLs

A queue URL looks like https://sqs.cdnshark.com/<broker id>/<queue name>, for example https://sqs.cdnshark.com/c12-orders/orders. Ask for it with GetQueueUrl instead of building it by hand.

What works

  • Create, list, get the URL of, purge and delete queues; queue attributes (message counts, retention, dead-letter rule).
  • Send and receive, one at a time or in batches of up to 10; long polling up to 20 seconds.
  • Message attributes (String, Number, Binary); SenderId, SentTimestamp, ApproximateReceiveCount.
  • Visibility timeout (default 30 seconds, up to 12 hours) and ChangeMessageVisibility.
  • Dead-letter queues through RedrivePolicy (maxReceiveCount), set when the queue is created.

Not yet

  • FIFO queues (.fifo), per-message delay (DelaySeconds), and changing a queue's settings after creating it (SetQueueAttributes): create a new queue instead.

Topics: see SNS Topics and Subscriptions.