RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Hyperscale Messaging in .NET with Amazon's Simple Queuing Service (SQS) : Page 4

Amazon SQS makes queuing messages across organizations over HTTP a snap with its Web service interface and Amazon-backed infrastructure. This article walks you through the process to get started using Amazon SQS to create and control queues and messages.

Add an Amazon SQS Web Reference
Add a Web reference to Amazon SQS WSDL by pointing to http://queue.amazonaws.com/doc/2006-04-01/QueueService.wsdl as shown in Figure 9. This will create com.amazonws.queue.* proxies to access the Amazon SQS service.

Figure 9. Web Reference to Amazon SQS WSDL: The figure shows how to find the Amazon SQS WSDL file to add the Web reference to your project.
Figure 10. The Completed Dashboard: The figure shows the completed Amazon SQS dashboard form, which lets you perform common queue and message operations.
The Amazon SQS Dashboard:
You are now ready to start using Amazon SQS. Among other files the downloadable code contains the Windows Form frmHyper (the file Hyper.cs—see Figure 10) and a wrapper class for Amazon SQS specific calls named AmazonSQS.cs.

The dashboard lets you list, create, and delete queues (delete is available only when a Queue is empty), and create and delete messages.

Most of the code is self-explanatory, but I'll go over couple of functions in the AmazonSQS.cs file. The getQueueNames() method shown below retrieves a list of queues. As shown, you first create an instance of QueueServiceWse (note the "Wse" suffix). All calls require you to construct parameters, which is this case is ListQueue. You pass this parameter to the ListQueues() function which returns the response, packaged as a ListQueueResponse instance. You then check for success and return the Queue list to the caller.

You will be prompted for a certificate password. This is the same password you supplied when you installed the certificate on Windows.

The getQueueService() method is a convenience function that creates an instance of QueueServiceWse and sets the AmazonSQS URL and the name of the WSE application policy you want to use.

   public static string[] getQueueNames()
      com.amazonaws.queue.QueueServiceWse queueService = 
      com.amazonaws.queue.ListQueues listQueues = new 
      com.amazonaws.queue.ListQueuesResponse listQueueResponse = 
      if (listQueueResponse == null || 
         listQueueResponse.ResponseStatus.StatusCode != SUCCESS)
         return null;
      string[] queueNames = listQueueResponse.QueueUrl;
      return queueNames;
   private static com.amazonaws.queue.QueueServiceWse 
      com.amazonaws.queue.QueueServiceWse queueService = new  
      queueService.Url = "http://queue.amazonaws.com/";
      return queueService;
To use the sendMessage() function, you first create an instance of MessageQueueWse (note the Wse suffix again) that points to a specific queue. Then you create an instance of Message, load the message with string content, and send it using the MessageQueueWse.sendMessage() method.

The getMessageQueueWse method is another convenience function that sets the WSE policy and Queue name. Here's the code for both methods:

   public static string sendMessage(string queueURL, string message)
      com.amazonaws.queue.MessageQueueWse messageQueue =  
         getMessageQueue(queueURL); ;
      com.amazonaws.queue.SendMessage sendMessage = new   
      sendMessage.MessageBody = message;
      com.amazonaws.queue.SendMessageResponse response =  
      if (response == null || response.ResponseStatus.StatusCode !=  
          return null;
      return response.MessageId;
   private static com.amazonaws.queue.MessageQueueWse 
      getMessageQueue(string queueURL)
      com.amazonaws.queue.MessageQueueWse messageQueue = new  
      messageQueue.Url = queueURL;
      return messageQueue;
The attached code contains a number of other useful functions that you can experiment with.

While Amazon SQS provides good basic queuing capabilities, it still does not provide capabilities such as such as journaling, acknowledgements, publish-subscribe, routing, etc that organizations have come to expect from messaging infrastructure. However, given the clout and weight Amazon carries, don't be surprised if such features begin showing up in the future as part of Amazon SQS.

Gautam Shah has been developing and integrating applications for over a decade. He has designed patented solutions that enable information sharing between government agencies. His interests center around J2EE, .NET, Open Source, BizTalk, Indian cooking, and anything that's vaguely interesting on the New York Times non-fiction bestseller list.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date