Write once, run anywhere….. This is Java as we know…. is it practically like that? Hmmm…. i don’t think so….
Running your once written application and deploying it in various containers according to your requirement is tedious and is very time consuming figuring out the nitty-gritties involved in doing so. Recently i had a project in which i am trying to do just that, write a web application, in fact a web service web application having capability of connecting to queues created in JBoss and Weblogic. I struggled initially trying to do this with JBoss (sounds amateur but i really did… yes as you call in Java world.. Jar hell). I struggled even beyond when i was trying to do this with Weblogic. I couldn’t do this till now but while searching in the internet there were some very cool blogs written on the Weblogic and JMS (yes basic stuff for senior developers). I felt these blogs as well written, easy to understand ones. Spending time writing such blogs really takes a hell lot of time and effort and in my blog i just want you guys to point to the right ones. I congratulate these bloggers and pat on their back. Here are some of these, purely with respect to Weblogic 11g and JMS.
Spring Batch is the first Java based lightweight, comprehensive framework for batch processing. Being built on top of the Spring Framework, it gives all the advantages of productive, POJO-based development approach.
Spring Batch is a lightweight, comprehensive batch framework designed to enable the development of robust batch applications vital for the daily operations of enterprise systems. Spring Batch builds upon the productivity, POJO-based development approach, and general ease of use capabilities people have come to know from the Spring Framework, while making it easy for developers to access and leverage more advanced enterprise services when necessary.
– Spring batch documentation (http://static.springsource.org/spring-batch/)
In this Chapter, we will cover Spring Batch in a comprehensive manner and aims at letting you use it in your enterprise application with less effort. The initial sections will introduce you to the core concepts on which Spring Batch is build and then later on delve deep into the various concepts in details along with appropriate code snippets.
Batch and Offline Processing
You would have heard these terms batch and offline processing for quite some time now and every time you have such requirement in your application you sit in front of the computer and start something fresh and code from scratch to realize this. With Spring Batch you now have a framework using which you can do these in a much better and cleaner manner. Before going through Spring Batch in detail, I would like to spend sometime explaining the usual business case which Spring Batch tries to achieve. Primary among these are batch and offline processing.
Batch applications needs to process high volume of business critical transactional data in an efficient manner. A typical batch program does the following:
Reads a large amount of data from database, file or queue as the case may be.
Processes the data according to the business requirement in an efficient manner.
Writes back the modified/processed data to database, file or queue as the case may be.
Batch is a group of similar or identical items and the pseudo code for this can be shown in Figure 23-1 below.
Figure 23-1. Pseudocode for a typical Batch
In most modern day applications there requires capability processing client request in offline manner. Offline processing differs from online/real-time processing with respect to the following aspects as outlined below:
Processing of processes which are long-running and which occurs beyond usual office hours
Non-interactive in nature and often requires appropriate logic capable of handling errors and taking necessary actions like restart in some cases and so forth.
Processing of processes which have large amount of data not fitting into a single transaction.
Some of the common examples of batch and offline processing are as given below, so that you can understand the use of Spring Batch and appreciate what it delivers out-of-box for you.
Large scale output jobs which need to run on a timely manner. For example; sales report spanning whole month or even whole year.
Import/export handling of data. For example; ETL (Extract-Transform-Load) jobs, data synchronization jobs etc.
Various close of business jobs. For example; sales report spanning a day, business level reporting etc.
The lack of standard, reusable batch architecture has resulted in the proliferation of many one-off, in-house solutions developed within client enterprise IT functions.
– Spring batch documentation (http://static.springsource.org/spring-batch/)
Why a framework?
So why would you need a framework for implementing batch? Why can’t we use a “for loop” for doing such batch jobs? We need to have a framework which addresses not only running a bunch of code in a loop fashion but also to have other features/capabilities/business scenarios as listed below (as detailed in Spring Batch documentation):
Commit batch processes periodically; Capability of committing the processed data at times due to various business reasons.
Staged, enterprise message-driven processing
Concurrent batch processing; parallel processing of a job
Massively parallel batch processing
Sequential processing of dependent steps with extensions to workflow-driven batches
Manual or scheduled restart after failure
Whole batch transaction: for cases with a small batch size or existing stored procedure s/scripts
Any modern application does not live in isolation. To realize the business requirements it has to communicate with customers of varied types and other applications in variety of ways. Application integration lets your application do this and in modern day applications, this is crucial for any application. Spring Integration aids in application integration that lets applications share data and services with each other making it connect with varied kind of users.
The Spring Integration is an open-source; simple integration framework that leverages the capabilities of widely adopted Spring Framework making application integration easy and simpler to implement.
This Chapter will help you start with Spring Integration and will aid you in achieving the various integration requirement in your application. I am sure after reading through this Chapter you will have one more weapon up your sleeves which you can use and reap benefits from its high level of integration capabilities.
Spring Integration Goals and Principles
Spring Integration is motivated by the following goals:
Provide a simple model for implementing complex enterprise integration solutions.
Facilitate asynchronous, message-driven behavior within a Spring-based application.
Promote intuitive, incremental adoption for existing Spring users.
Spring Integration is guided by the following principles:
Components should be loosely coupled for modularity and testability.
The framework should enforce separation of concerns between business logic and integration logic.
Extension points should be abstract in nature but within well-defined boundaries to promote reuse and portability.
The goals and principles of Spring Integration is as quoted in the Spring Integration Reference Manual.
Spring Integration Benefits
Spring Integration benefits can be summarized as follows:
Loose coupling between components – brings about development of small and focused components that caters to specific role and responsibility. This eases testing and promotes reuse largely.
Helps to separate integration and processing logic – Spring Integration pitches-in, handling message routing, transformation etc. and eases the application developer from this. Due to high level of configuration based integration style, easily processing can be switched between synchronous and asynchronous with no change in the code that is handy in this ever-changing business application scenario.
Promotes Event-driven architecture – No hard coded process flows and capability to easily change and expend these flows according to application requirement. Single word that can be used is adaptability.
Enterprise Integration Pattern (EIP)
Enterprise Integration Patterns is a book by Gregor Hohpe and Bobby Woolf and describes a number of design patterns for the use of enterprise application integration and message-oriented middleware. Enterprise Integration Patterns can be implemented without coding using Spring Integration or Apache Camel.
Enterprise application integration is an integration framework composed of a collection of technologies and services, which form a middleware to enable integration of systems and applications across the enterprise.
Spring Integration brings the power of Dependency Injection (DI) that Spring Framework is well known for and EIP patterns implementation together to nicely manage the resources and lets you focus on business logic rather than messaging infrastructure code.
Spring Integration Namespaces
For easing the various integration style configurations, Spring Integration has dedicated namespaces for each of them. Table 22-1 gives details of Spring Integration namespace in a tabular form for easy reading and understanding.
Defines the configuration elements for Spring Integration’s HttpInvoker adapters. NOTE: The http-invoker support is deprecated as of 2.0.x. It is recommended to use the REST-based HTTP adapters instead.