Showing posts with label architecture. Show all posts
Showing posts with label architecture. Show all posts

Monday, March 29, 2010

Executing Asynchronous Actions in a Web Application

Web applications need to provide instant response to end users, however not all requests can be served instantly due to a variety of constraints on infrastructure the application must live with. In an enterprise web applications there could a variety of long running tasks initiated by user request. To handle such task, the request could be queued for later processing and user is presented with a message to check status at a later time.  For some requests a part of necessary processing could be done instantly and remaining could be done at a later time.

Queuing a request requires adding extra infrastructure to web applications. Request could be queued in a single instance of share data structure across the application. Application threads running in background can read the queue data structure and act on queue messages. Rather than writing this framework/infrastructure enterprise class open source libraries could be utilized.  ActiveMQ provides a robust queuing solution and Apache Camel provides processing queued actions. Both libraries can be used in embedded or standalone fashion.

Architecture:

ServletContextListener initialize the ActiveMQ Broker and CamelContext, queues and routes are setup.

Have web action/controller write to ActiveMQ queue.

Write classes/camel routes to read from queue .

Tuesday, February 17, 2009

Convention Over Configuration

Convention Over Configuration refers to predefining conventions (for example a standard location where a file/directory is expected or following a naming schema for resources) for underlying frameworks/applications so that framework/application can work without having to specify these entries in configuration files. This enable end user of software to get going without lot of configuration, however a user/developer still has flexibility to configure in unconventional way.

Another term used is "Configuration by exception", configure when there is exception to rule(convention).

Example of these are plenty,

Build tool Maven expect source files to be in certain conventional location (like java classes reside in main\java\src ), however user can still specify other location for source code.

Hibernate Data mappings can work without specifying mapping files by following convention for Table names matching Class names.

Advantages:
-End user/developer can get going without too much configuration or too much boiler plate code(code that is repetitive and standard).
-Provides structure/discipline to a projects, certain things should be done using conventions, like source files should be named certain ways. Convention makes it easier for developer who is familiar with convention to jump into a project, as the project is organized in a familiar way. (On the flip side a developer who is new to framework, need to learn conventions!)


Disadvantages:
Underlying framework/application has to write code for convention and for configuration.
Convention have to be learned.