Amazon Web Services Message Queuing CSharp


I was trying to build a custom dashboard in a .net desktop application that showed the status of all my Amazon Web Services (AWS) services. So I searched the internet and looked at this link . And in just a few minutes, I was able to build a service status dashboard fairly quickly. I continued to explore the .net SDK (Software Development Kit) and built a simple Amazon Web Services Message Queuing CSharp Application. This AWS SQS call in Microsoft.Net was surprisingly simple. This post describes the steps to create a queue in AWS SQS and send a message to the queue from a .net console application written in c#. All the steps are shown in my youtube video with the link shown below.

Amazon Web Services Message Queuing CSharp Application Architecture

The diagram below shows the high level architecture of the Application.

Amazon Web Services Message Queuing CSharp
Figure 1: AWS SQS call in c#


The steps for sending a message to a queue are described below.

1. Create an AWS Account if you do not have one. You can sign up at this for the free web tier and get started here. This post assumes you are already signed up with AWS.

2. Download AWS SDK for .net from this link.

3. The video explains how to create a queue in SQS. You can create a queue programmatically in .net or several other supported languages and use AWS API (Application Programming Interface). But, In this video, we will create a queue in AWS from the AWS console.

4. Also included in this video are the steps to create a user just for sending messages to the message queue. A group with appropriate permissions is created and the user is assigned to this group.

4. Finally, we write a simple console app in .net to send a message to the message queue.

Source Code:

                //this is the interface to SQS Service
                AmazonSQSClient SQSClient = new AmazonSQSClient();
               //create the message object
                SendMessageRequest MessageRequest = new SendMessageRequest();
                //read this URL from the AWS SQS console 
                MessageRequest.QueueUrl = "your queue URL";
                //set the message text
                MessageRequest.MessageBody = "This is a test";
                //send the message
                //prevent the console window from closing
            catch (Exception ex)
                //display exception
                //prevent the console window from closing

Please note:

  1. The AmazonSQSClient instance has very intuitive API. You can perform many common message queue activities (add queue, delete queue, send message, read message etc.) by invoking methods on this object. You can also invoke methods asynchronously which is somewhat expected when dealing with message queues.
  2. The code in this post works at the time of writing this post (January 15, 2017).
  3. No warranty is provided with the code or any documentation in this article.

Your feedback (positive or negative) is important to me. I’d love to get your comments on this article. Also, I’ll post several other posts and videos on AWS Service in the near future.