REST-style Actionscript programming interface for ...

14 downloads 100643 Views 505KB Size Report
does not needlessly force the user to call methods in a strict ... sendMessage - add messages to a specified queue. ... iPhone / Android / BlackBerry user opens.
REST-style Actionscript programming interface for message distribution using Amazon Simple Queue Service K. Popovic, Z. Hocenski Siemens d.d. / Communications, Media and Technology, Osijek, Croatia Faculty of Electrical Engineering / Institute of Automation and Process Computing, Osijek, Croatia [email protected] Abstract - Amazon Simple Queue Service (Amazon SQS) is a message-oriented middleware in the cloud using software as a service model. It aims to eliminate the traditional overhead associated with operating in-house messaging infrastructures by providing reduced costs, simplified access to messaging resources, scalability and reliability. In order to provide those benefits Amazon SQS leverages cloud resources such as storage, network, memory, processing capacity. Using virtually unlimited cloud computing resources, an Amazon SQS provides an internet scale messaging platform. This paper presents benefits and examples of Amazon SQS programming interface developed in Actionscript 3.0 object-oriented programming language. This interface was developed to enable Adobe Flex mobile developers to facilitate integration efforts within organizations and between them using mobile devices (tablets and smartphones).

I.

INTRODUCTION

Mobile computing has drastically impacted the social and commercial aspects of our society [1]. Seeing the explosion of mobile applications in the consumer world, companies can't avoid dreaming about revolutionizing their businesses with the presence of mobile applications. The ability of extending business capabilities to mobile devices (tablets and smartphones) leads the priority list of most CIOs (Chief Information Officer) [2]. However, the path to enterprise mobility goes beyond building sporadic applications for a specific line of business systems. Companies embarking on the enterprise mobility journey need cohesive strategies for important mobile infrastructure aspects such as device management, identity, security, and monitoring, that are required to provide a true enterprise mobility experience. During the last few years, cloud infrastructures have pushed the frontiers of software development to areas never before imagined. In the context of enterprise mobility, the cloud model and services present a unique model to simplify the challenges of the traditional enterprise mobility model and to open new possibilities in the space. Conceptually, an enterprise cloud mobility platform removes the complexities of the mobile enterprise server from the corporate network by placing it in a cloud infrastructure where it can leverage various cloud services to enable its native capabilities. A cloud enterprise mobility infrastructure represents a higher simpler model from the infrastructure standpoint than its on-premise

counterpart. In this model organizations are only responsible for deploying the portion of the applications that interact with the web services and message queues. Message and data exchange are an essential aspect of any enterprise mobile application [3]. The ability to exchange messages or consume data from on-premise or cloud environments in a mobile device is, arguably, the most relevant element of an enterprise mobility platform. The key is to build components that do not have tight dependencies on each other, so that if one component were to die (fail), sleep (not respond) or remain busy (slow to respond) for some reason, the other components in the system are built so as to continue to work as if no failure is happening. In essence, loose coupling isolates the various layers and components so that each component interacts asynchronously with the others and treats them as a black box. Loosely coupled system can be build using messaging queues. If a queue is used to connect any two components together, it can provide concurrency, high availability and mitigate load spikes. Today, technologies such as Amazon SQS [4], CloudMQ [5], Linxter [6], Microsoft Azure Message Queue [7] and others offer simple cloud-based messaging services to broker the communication between different endpoints. In this paper benefits and examples of Amazon SQS programming interface developed in Actionscript 3.0 object-oriented programming language (library name: as3awsSDK.swc) are presented [8]. Interface is developed as publicly available Community Contributed Software for thin clients [9]. The goal of this paper is to present developed Amazon SQS programming application interface for Actionscript 3.0 and its benefits for Flex developer community. The paper is organized as follows: Section II lists recent available software development kits from prominent cloud providers and open-source community. Also benefits of Amazon Simple Queue Service (Amazon SQS) are considered, and mobile application portability issue solution is recommended. Section III presents architecture of Amazon SQS API for Actionscript 3.0 and one use case sample how it can be used in practice.

II.

III.

RELATED WORK

As of recent, software development kits available from prominent cloud providers and open-source community provide APIs (libraries) that hide much of the lower-level complexity, including authentication, request retries, and error handling. They take the complexity out of coding directly against a web service interface. TABLE I shows available software development kits from different cloud providers. TABLE I. SOFTWARE DEVELOPMENT KITS Software Development Kit

Cloud provider Microsoft

Linxter

CloudMQ

Amazon

Home computer Java .NET PHP Ruby Mobile iOS Android

Amazon SQS is used as message-passing mechanism between components. It acts as glue that holds together different functional components. This not only helps in making the different components loosely coupled, but also helps in building a more failure resilient system overall. If one component is receiving and processing requests faster than other components (an unbalanced producer consumer situation), buffering will help make the overall system more resilient to bursts of traffic (or load). Amazon SQS acts as a transient buffer between two or more components (controllers). If a message is sent directly to a component, the receiver will need to consume it at a rate dictated by the sender. For example, if the system was slow or if the launch time of the cluster was more than expected, the overall system would slow down, as it would just have to wait. With message queues, sender and receiver are decoupled and the queue service smoothens out any “spiky” message traffic. These service benefits can be used by mobile devices in an innovative, simple and transparent way. A. Characteristics of a good API What are characteristics of a good application programming interface (API)? Answer to this question has to be known to software developers before API implementation. 

Easy to learn (steeper learning curve) - an easy-tolearn API features, consistent naming conventions and patterns, economy of concepts, and predictability. It uses the same name for the same concept, and different names for different concepts. A minimal API is easy to memorize because there is little to remember. A consistent API is easy to memorize because you can reapply what you learned in one part of the API when using a different part. The semantics should be simple and clear, and follow the principle of least surprise.



Hard to misuse - A well-designed API makes it easier to write correct code than incorrect code, and encourages good programming practices. It does not needlessly force the user to call methods in a strict order or to be aware of implicit side effects or semantic oddities.



Easy to read and maintain code that uses it readable code can be concise or verbose. Either way, it is always at the right level of abstraction— neither hiding important things nor forcing the software developer to specify irrelevant information.



Easy to extend - Libraries grow over time. New classes appear. Existing classes get new methods, methods get new parameters, and enums get new enum values. APIs should be designed with this in mind. The larger the API, the more likely the clashes between the new concepts and the existing concepts. In addition, binary compatibility

BlackBerry

Each provider provides several publicly available libraries for different development environments. For proper use developer needs to have technical knowledge about the environment in which he/she develops. This can be time consuming and costly because e.g. for mobile development it is necessary to have iOS, BlackBerry and Android knowledge. Also, the same application needs to be developed three times. Solution to the portability issue is to use technology which enables developers to write code once, and run anywhere. This is possible since June, 2011 using Adobe Flex SDK (version 4.5 or later) framework [10]. Flex is a highly productive, open source framework for building and maintaining expressive web applications that deploy consistently on all major browsers, desktops and operating systems. This means that source code written in Actionscript 3.0 can be also compiled for all mobile devices. Knowing that, it was prudent to develop an Actionscript 3.0 library for one of cloud providers which offer message queue service. Purpose of this library is to enable Adobe Flex developers to facilitate integration efforts within organizations and between them using mobile devices. The benefit of doing it this way has impact on application maintenance costs. Amazon SQS owned by Amazon Inc. was chosen as message middleware because of proven maturity when compared to others and due to Amazon’s vast cloud market share.

AMAZON SQS APPLICATION PROGRAMMING INTERFACE FOR ACTIONSCRIPT 3.0

concerns must be taken into consideration during the original design phase.



deleteMessage - remove a previously received message from a specified queue.

Guidance above was taken as main beacon toward good API during the design and development phase of Amazon SQS API for Actionscript 3.0. After development phase it was shown that developers should strive for minimalism and consistency, but only to the extent that they contribute to meeting the criteria listed above. Consistency coincides broadly with conceptual integrity, the principle that a complex system should have a coherent design, reflecting the vision of one architect.



deleteMessageBatch - remove multiple previously received messages from a specified queue.



setQueueAttributes - control queue settings like the amount of time that messages are locked after being read so they cannot be read again.



getQueueAttributes - get information about a queue like the number of messages in it.



getQueueUrl - get the queue URL.

Quote from F.P. Brooks [11]: „I contend that conceptual integrity is the most important consideration in system design. It is better to have a system omit certain anomalous features and improvements, but to reflect one set of design ideas, than to have one that contains many good but independent and uncoordinated ideas.“



addPermission - add queue sharing for another AWS account for a specified queue.



removePermission - remove an Amazon AWS account from queue sharing for a specified queue.



releaseResources – this is a special function which removes all event listeners and releases any resources that might be held open on client side. Execution of this method minimizes memory consumption.

B. Architecture of developed Amazon SQS API for Actionscript 3.0 – as3awsSDK.swc Amazon SQS library for Actionscript 3.0 as3awsSDK.swc is consisted of three basic model types: event model, interface model and class model. Interface model employs a simple interface com.amazonaws.services.sqs.AmazonSQS (defined in Amazon SQS WSDL version 2011-10-01) that is easy to use and extend (see Figure 1).

Figure 1. Basic architecture overview of Amazon SQS API for Actionscript 3.0

The following AmazonSQSClient requests defined by interface AmazonSQS are provided: 

createQueue - create queues for use with your Amazon AWS account.



listQueues - list your existing queues.



deleteQueue - delete one of your queues.



sendMessage - add messages to a specified queue.



sendMessageBatch - add multiple messages to a specified queue.



receiveMessage - return one or more messages from a specified queue.



changeMessageVisibility - change the visibility timeout of previously received message.



changeMessageVisibilityBatch - change the visibility timeout of multiple previously received messages.

Class model contains two core classes: 

com.amazonaws.AmazonWebServiceClient – abstract class which performs data stream encoding using createURLRequest protected function. It is designed as a base class which can be reused by other Amazon AWS services, e.g. Amazon Cloudwatch monitoring service [12], DynamoDB noSQL database [13], etc.



com.amazonaws.services.sqs.AmazonSQSClient – queue client which contains implemented and documented asynchronous queue service public functions. Each function is unique and there is no dependence between each other.

Event model uses interface flash.events.IEventDispatcher. The IEventDispatcher interface defines methods for adding or removing event listeners, checks whether specific types of event listeners are registered, and dispatches events. Event targets are an important part of the Flash® Player and Adobe AIR event model. The event target serves as the focal point for how events flow through the display list hierarchy. When an HTTP/HTTPS COMPLETE event occurs, an event object is dispatched into the event flow from the root of the display list. The event object makes a round-trip journey to the event target, which is conceptually divided into three phases: the capture phase includes the journey from the root to the last node before the event target's node; the target phase includes only the event target node; and the bubbling phase includes any subsequent nodes encountered on the return trip to the root of the display list. HTTP(s) request responses in XML format are caught by an event model, parsed and deserialized to Actionscript 3.0 result object for easier user handling. During XML namespace parsing, response format and

mandatory parameters are checked if they are properly formatted, if not exception will be thrown. Usage of these three models guarantees consistency in future Amazon SQS API library upgrades. This means that Amazon SQS API can be used as a template for creation of new services in the future. C. How to use Amazon SQS API for Actionscript 3.0 For proper programmatic usage it is necessary to understand that API only works in asynchronous environment because it is based on Adobe Flash and Adobe AIR technology. Every request (sendMessage function, see Figure 2) has assigned two callback functions called when a specific event occurs.

Figure 2. Amazon SQS sendMessage sample for Actionscript 3.0

ResultHandler function is called when positive HTTP/ HTTPS response event occurs (result code 200 OK) and the faultHandler for negative event (result code >= 400). Other functions defined in interface com.amazonaws.services.sqs.AmazonSQS are used in the similar way. This means that developers will have a steep learning curve and become quite proficient in API usage with a minimum amount of effort/time. D. Taxi reservation service – usecase sample One of possible usage of mobile device and custom developed as3awsSDK.swc library is for connecting to Amazon SQS service to store taxi reservation messages (see Figure 3). It can be quite useful when taxi dispatcher phone lines are busy. The mobile application which does reservation is portable to all mobile devices because it must be compiled with Flex compiler for proper library usage.

Figure 3. Taxi reservation service

Use case description: 

iPhone / Android / BlackBerry user opens Taxi reservation mobile application.



User enters his first name, last name, pickup location, dropdown location, number of people and a phone number.



Reservation request is send towards Amazon SQS queue TAXI_RESERVATION and stored there until service consumer (e.g. harvest server) pick it up.



Harvest server checks every e.g. 30 seconds TAXI_RESERVATION queue status and harvests messages if there are any. When the message is consumed from queue it needs to be processed and stored into a database. After the message is consumed it needs to be deleted from the TAXI_RESERVATION queue.



If a user reservation request can be served (taxi car is available) dispatcher will call the user and confirm reservation or send an SMS / e-mail.

The advantage of working with queues is that if the harvest server is offline reservation records can be consumed later after harvest server comes back online. With this degree of independence, taxi software components are protected from each other and can better recover from component failure. If the SOA (Service Oriented Architecture) is designed correctly, the failure of a single component should not take down other components in the system and thus loose coupling creates architectures that are more resilient. Moreover, this also lends itself better to creating a failover subsystem, moving from one instance of a component to another without affecting the other components in the SOA. IV.

CONLUSION

In this paper Amazon Simple Queue Service (Amazon SQS) programming application interface for Actionscript 3.0 (as3awsSDK.swc) has been presented and its benefits for Flex developer community. Most valuable advantage of programming application interface for Actionscript 3.0 (compiled with Flex SDK compiler 4.5 or greater) from technical point of view is portability. Code compiled with the Flex SDK compiler follows the slogan “write code once, and run anywhere”. It enables developers to deploy

cloud message queue enabled mobile application on several different mobile OS result of which are reduced development costs and time. During the time of writing this paper library was downloaded by open source community 176 times.

[7]

[8]

[9]

REFERENCES [1]

[2]

[3]

[4] [5] [6]

Gartner, Inc. (information technology research and advisory company), Gartner Forecasts Mobile App Store Revenues, http://techcrunch.com/2011/01/26/mobile-app-store-15-billion2011/, February 05, 2012. Sysbase (an SAP company), Mobile Enterprise Application Platform, http://www.sybase.com/mobilize/strategic-mobility, February 05, 2012. W. R. Schulte, “Cloud-Based Messaging Services and Technology Are Positioned for Rapid Growth”, Gartner research paper, January 24, 2011. Amazon Inc., Simple Queue Service, http://aws.amazon.com/sqs/, February 05, 2012. CloudMQ, Message Queuing as a Service, http://www.cloudmq.com/, February 05, 2012. Linxter, Message-Orianted Cloud Middleware, http://www.cloudmessaging.net/, February 05, 2012.

[10]

[11]

[12] [13]

Microsoft Azure Message Queue, Queue Service Rest API, http://msdn.microsoft.com/enus/library/windowsazure/dd179363.aspx, February 05, 2012. K. Popovic, Amazon SQS API library (version 1.4.1), https://bitbucket.org/Kresimir/as3awssdk/overview, February 05, 2012. Amazon Inc, Amazon AWS SDK library (actionscript 3.0), Community Contributed Software, http://aws.amazon.com/developertools/0564396818170928, May 03, 2011. Adobe Inc. Adobe Open Source Flex SDK compiler, http://opensource.adobe.com/wiki/display/flexsdk/Flex+SDK, February 05, 2012. F.P. Brooks, “The Mythical Man-Month: Essays on Software Engineering”, Second Edition, ISBN-10: 0201835959, ISBN-13: 978-0201835953, August 12, 1995. Amazon Inc, Cloudwatch service, http://aws.amazon.com/cloudwatch/, February 05, 2012. Amazoin Inc, DynamoDB noSQL database, http://aws.amazon.com/dynamodb/, February 05, 2012.