SNS Topics and Subscriptions
A topic sends each message it receives to every queue subscribed to it, so one event can reach several services. SharkMQ speaks the Amazon SNS API at https://sns.cdnshark.com, with the same access key id and secret as SQS.
Example (Python)
import boto3, os
kw = dict(region_name="us-east-1", aws_access_key_id=os.environ["SHARKMQ_KEY"],
aws_secret_access_key=os.environ["SHARKMQ_SECRET"])
sns = boto3.client("sns", endpoint_url="https://sns.cdnshark.com", **kw)
sqs = boto3.client("sqs", endpoint_url="https://sqs.cdnshark.com", **kw)
topic = sns.create_topic(Name="order-events")["TopicArn"]
url = sqs.create_queue(QueueName="billing")["QueueUrl"]
arn = sqs.get_queue_attributes(QueueUrl=url, AttributeNames=["QueueArn"])["Attributes"]["QueueArn"]
sns.subscribe(TopicArn=topic, Protocol="sqs", Endpoint=arn)
sns.publish(TopicArn=topic, Message="order 42 created")
Filter policies
A subscription can take only some messages, chosen by their message attributes:
sns.subscribe(TopicArn=topic, Protocol="sqs", Endpoint=arn,
Attributes={"FilterPolicy": '{"tier": ["gold"], "amount": [{"numeric": [">", 100]}]}'})
Supported: exact values, prefix, suffix, equals-ignore-case, anything-but, numeric comparisons and ranges, exists, and lists. Every attribute in the policy must match; any value in a list may match.
Raw or wrapped messages
By default a queue receives the message wrapped in the standard SNS JSON envelope (Type, MessageId, TopicArn, Message, MessageAttributes …). Set RawMessageDelivery to true on the subscription to receive only the message body, with the attributes as SQS message attributes.
What works
- Create, list and delete topics; subscribe and unsubscribe SQS queues of the same broker; list subscriptions; get and set subscription attributes.
PublishandPublishBatch(up to 10), with message attributes and a subject.
Not yet
- HTTPS, email and SMS subscriptions,
MessageStructure=json, and FIFO topics. - The envelope's
Signaturefield is empty. SQS subscribers normally do not check it.