Spring Integration

Mark Fisher of SpringSource gave a talk on Spring Integration at Monday night's Boston Java Meetup. Mark has been with SpringSource for 2.5 years. He is a Spring committer and leads the Spring Integration project.

Spring Integration 1.0 is scheduled to be released in about 1.5 months. Spring Integration is an application of many of the ideas in the book Enterprise Integration Patterns and its related web site.

Mark began with an introduction to Spring. Fundamentally, Spring is an inversion of control (IoC) container, offering dependency injection, aspect oriented programming (AOP), and enterprise support libraries. It supports a POJO based programming model. He gave an overview of Spring features:
  • In Spring 2.5, you can use annotations instead of or in addition to the usual Spring XML configuration files.
  • @Autowired annotation
  • @Test annotation, the EasyMock library
  • AOP for transactions: uses the @Transactional annotation, delegates to the transactionManager that you wired in the XML config. Mark recommends using AOP for anything that's not in your business logic/problem domain, that you'll apply to numerous objects or methods. Doing so lets you focus on business logic.
  • JDBC templates, e.g. getSimpleJdbctemplate().query("select id, balance from account here customer_name=?", accountMapper, customer). In his example, he also uses a PramaterizedRowMapper. The advantage of the JDBC and other templates is that Spring handles the mundane set up work and exception handling for you.
  • JMS templates: Configuring a JMS listener is easy. They are a complete replacement for message-driven beans, and no EJB container required.
Some consequences of using Spring are that your domain model is simplified, layers enforce separation of concerns, and interface contracts promote loose coupling.

A meetup member asked why Spring uses AOP instead of @Interceptor. Mark replied that a problem with that approach is that you must annotate each method @Interceptor everywhere--you can't use AOP cut points defined by regular expressions, for example. He commented that it is still an open question whether EJB3's Interceptor approach is powerful enough

Enterprise integration patterns
Mark continued with an overview of enterprise integration patterns:
  • Pipes and filters architecture: conceptually, just like Unix pipes and filters
  • Message: send Messages through the pipeline. A Message is just a wrapper around a Java object.
  • Message channel: decouples producers from consumers. Can bepoint-to-point or publish/subsribe.
  • Channel adapter: connects a source to the messaging system. Can be anything, like a message bean, a web request, or a file system object.
  • Service activator: lets you invoke any POJO method without the service knowing that it's being using that way
  • Message translator: a payload transformer, converts the type or format of a message
  • Content enricher, content flter: add to or remove from message content
  • Content based router: determines the target channel based on payload type, property value, or header attribute. Decides where to send message. For example, the router might send a message to either the VIP service or the standard service based on importance of sender.
  • Splitter and aggregator
Spring Integration API
Following that, Mark presented the Spring Integration API. In a nutshell, Spring Integration implements enterprise integration patterns in Spring. The primary implementation points are:
  • interface MessageSource.receive: receives messages
  • interface MessageTarget.send: sends messages
  • interface MessageChannel.send, .receive
  • interface MessageHandler.handle
  • Message Bus: aware of components (hadlers, sources), connects them to channels, turns everyting on, runs a task scheduler, creates message end points, and ties them to channels
As a user of Spring Integration, you will specify things in your XML config file or via your annotation-based configuration, e.g. @Handler. You won't, for example, implement the MessageSource interface directly in your business code. This is consistent with Spring's theme: use domain objects everywhere; don't write any special messaging code.

Mark showed us some great demos and code examples, all of which are included in the Spring Integration distribution.

Additional features on the Spring Integration road map include:
  • Additional XML support, including XSLT transformations
  • Quartz scheduling
  • Support for additional channels, including RMI, email, and more

No comments:


Related Posts with Thumbnails