advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the sample Amazon SQS Dashboard application.
Partners & Affiliates
advertisement
advertisement
advertisement
Rate this item | 0 users have rated this item.
Hyperscale Messaging in .NET with Amazon's Simple Queuing Service (SQS) (cont'd)
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.
advertisement


 
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 = 
         getQueueService();
   
      com.amazonaws.queue.ListQueues listQueues = new 
         com.amazonaws.queue.ListQueues();
    
      com.amazonaws.queue.ListQueuesResponse listQueueResponse = 
         queueService.ListQueues(listQueues);
   
      if (listQueueResponse == null || 
         listQueueResponse.ResponseStatus.StatusCode != SUCCESS)
         return null;
   
      string[] queueNames = listQueueResponse.QueueUrl;
      return queueNames;
   }
   private static com.amazonaws.queue.QueueServiceWse 
      getQueueService()
   
   {
      com.amazonaws.queue.QueueServiceWse queueService = new  
         com.amazonaws.queue.QueueServiceWse();
      queueService.Url = "http://queue.amazonaws.com/";
      queueService.SetPolicy("HyperscalePolicy");
      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   
      com.amazonaws.queue.SendMessage();
      sendMessage.MessageBody = message;
   
      com.amazonaws.queue.SendMessageResponse response =  
         messageQueue.SendMessage(sendMessage);
      if (response == null || response.ResponseStatus.StatusCode !=  
         SUCCESS)
      {
          return null;
      }
      return response.MessageId;
   }
   
   
   private static com.amazonaws.queue.MessageQueueWse 
      getMessageQueue(string queueURL)
   {
      com.amazonaws.queue.MessageQueueWse messageQueue = new  
         com.amazonaws.queue.MessageQueueWse();
      messageQueue.SetPolicy("HyperscalePolicy");
      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.

Previous Page: Building the SQS Dashboard  


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.
Page 1: IntroductionPage 3: Building the SQS Dashboard
Page 2: Getting Started with SQSPage 4: Add an Amazon SQS Web Reference
Please rate this item (5=best)
 1  2  3  4  5
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Help  |   Site Map  |   Network Map  |   About


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers