SNS

How to Implement the Pub/Sub Pattern with .NET, Amazon SNS and CloudEvents

There is no shortage of technologies that allow for building pub-sub messaging systems. Off the cuff, I can think of NServiceBus, Azure Service Bus, RabbitMQ, MassTransit, etc. However, Amazon Simple Notification Service or SNS, may be the easiest to implement as well as the most flexible solution.  

What Exactly is the Pub-Sub Pattern?

In essence, the pub-sub pattern or publish-subscribe pattern, is a messaging pattern in software architecture where a publisher creates a message and sends it to a predetermined location for one or more subscribers to consume. The predetermined location has different names and has differing structures in different systems. However, in this tutorial we will refer to that predetermined location as a “topic”. To look at it from the consumer’s perspective, a consumer would subscribe to a topic of interest and when the publisher publishes a message to the topic, the consumer and any other subscribed consumers would receive the message.

Create an SQS Queue and an SNS Topic and Subscription using the AWS CLI

AWS gives engineers many ways to accomplish many tasks. Here we will look at creating both a Simple Notification Service topic as well as a Simple Queue Service queue and then creating an SNS subscription “linking” the two. All the while, we will exclusively use the AWS CLI to accomplish the task. This exercise could also be carried out in  the AWS console as well as one of the AWS SDKs and if you are proficient in an AWS SDK or the console, feel free to use one of those tools to view the changes being made while we move through this solution.