Spring Integration: a new addition to the Spring portfolio

Mark Fisher

Yesterday morning I presented a 2-part session at The Spring Experience entitled "Enterprise Integration Patterns with Spring". The first presentation included an overview of core Spring support for enterprise integration - including JMS, remoting, JMX, scheduling, and email. That presentation also included a high-level discussion of several of the Enterprise Integration Patterns introduced in the book of the same name by Gregor Hohpe and Bobby Woolf. In the second presentation, I officially unveiled "Spring Integration" - a new addition to the Spring portfolio. Spring Integration builds upon Spring's core support while providing a higher level of abstraction largely inspired by those patterns. Here I would like to provide a brief overview of the topics I discussed in that session. You can also read two articles about Spring Integration that appeared yesterday on eWeek and InfoWorld.

First I described the goals and motivations of Spring Integration - namely that the implementation model should be simple and non-invasive - providing philosophical consistency with core Spring principles. Business components should be decoupled from the underlying messaging infrastructure and therefore testable in isolation. The framework should hide the complexities of thread-management while still enabling full configurability of thread pools, queue capacities, and scheduling parameters. Custom extension points should be provided as well-defined strategy interfaces. It should be possible to use dynamic languages for integration logic, such as routing and transformation. Configuration options should include generic XML, domain-specific namespace support, and annotations. While building upon these core Spring principles, the implementation will be leveraging core Spring features including lifecycle management, task execution, aspect-oriented programming, transaction management, dynamic language support, JMS, remoting, mail, and scheduling.

By following those goals and motivations, Spring Integration will simplify development of enterprise integration solutions. Since the concepts and implementations are so consistent, it will facilitate incremental adoption for existing Spring users who are beginning to explore SOA and EDA. Finally, as a member of the Spring portfolio, it will provide seamless compatibility and timely co-evolution with other products in the Spring portfolio.

After discussing those goals and motivations, I walked through the API. The core components are the Message, MessageChannel, and MessageEndpoint. A Message is a container for any type of data as well as a header that provides common messaging properties (id, correlation id, expiration, return address, sequence info, etc.). A MessageChannel provides send and receive methods, and those methods accept a timeout. The receive methods also accept a MessageSelector with a single method: boolean accept(Message message). Here is the basic interface definition for a MessageChannel

public interface MessageChannel {
    boolean send(Message message);
    boolean send(Message message, long timeout);
    Message receive();
    Message receive(long timeout);
    Message receive(MessageSelector selector);
    Message receive(MessageSelector selector, long timeout);
}

A MessageEndpoint connects a MessageHandler to an inbound MessageChannel and/or an outbound MessageChannel. The MessageHandler is a generic interface that provides a foundation for transformers, routers, and any other component that handles an incoming Message.

public interface MessageHandler {
    Message handle(Message message);
}

Channel Adapters are used for sending to and receiving from external data sources. For example, to send a JMS message, an OutboundJmsChannelAdapter is provided. When configuring the messaging system, that adapter can be sent messages as if it were just another channel. A MessageBus wires together the various endpoints and channels. This is consistent with the way that a Spring ApplicationContext wires together objects. In fact, the MessageBus is itself an ApplicationContextAware object and detects the various messaging components from its context. This is very similar to the behavior of a DispatcherServlet in a Spring MVC application. Spring Integration's namespace support provides a concise way to configure the components:

<integration:message-bus/>

<integration:channel id="quotes"/>

<integration:endpoint input-channel="quotes" handler-ref="logger" handler-method="log">
   <integration:consumer period="1000"/>
</integration:endpoint>

Alternatively, there is support for annotations:

@MessageEndpoint(input=“inputChannel�, defaultOutput=“outputChannel�)�
public class SimpleAnnotatedEndpoint {

    @Handler
    public String sayHello(String name) {
        return "Hello " + name;
    }
}

Annotations for transformation and routing (e.g. @Router, @Splitter, and @Aggregator) will also be supported. Additionally, "channel adapters" can be created with annotations, such as @Polled for input and @DefaultOutput for output if the handler returns a message and that message does not provide its own 'return address'. For example, the following endpoint would print out "Hello World" every 5 seconds:

@MessageEndpoint
public class SampleAnnotatedEndpoint {

    @Polled(period=5000)â€?
    public String getName() {
        return "World";
    }

    @Handler
    public String sayHello(String name) {
        return "Hello " + name;
    }

    @DefaultOutput
    public void display(String message) {
        System.out.println(message);
    }
}

The @MessageEndpoint also works "out of the box" with Spring 2.5's new component-detection capabilities. Therefore the above example would not require any XML configuration at all. For an even simpler way to create an endpoint for a single method, you can use the @Subscriber annotation on that method:

@Subscriber(channel=“testChannel�)�
public void test(String s) {
    …
}

That annotation and a corresponding @Publisher are both enabled with a single 'annotation-driven' element from the Spring Integration namespace. The @Publisher builds upon Spring AOP in order to publish the return-value of a method. It will also support other advice types, such as 'before' and 'after-throwing'.

The examples above are based on a 0.5 version of Spring Integration. Therefore, these interfaces and annotations are subject to change. In fact, we are particularly interested in feedback during this early phase. I have already had several interesting discussions with attendees here at The Spring Experience who are very excited by the possibilities of this new offering. The 1.0 Milestone 1 release will be available in early January, and the 1.0 Final release will be available by Q2 2008. The 1.0 Final version will support multiple configuration formats (XML, namespace, and annotations), point-to-point and publish/subscribe channels, and several adapters (minimally: JMS, RMI, HttpInvoker, Hessian/Burlap, File, EMail, JDBC, stream, and Spring ApplicationEvents). It will also work seamlessly with Spring's transaction management and dynamic language support. Finally, it will integrate with other Spring portfolio products such as Spring Web Services, Spring Web Flow, Spring MVC, Spring Batch, and Spring Security. Of course, we will also be working closely with the Spring Dynamic Modules project to OSGi-enable the messaging components.

Stay tuned to this blog for more information in the coming days including the public availability of the code repository. Also, be sure to read those articles that appeared yesterday at eWeek and InfoWorld.

 

24 responses


  1. Hi Mark

    Where can I find the 0.5 version?

    Best Regards
    Thomas


  2. Why does this feel like a reimplementation of http://activemq.apache.org/camel/ ?

    What is different?


  3. [quote comment="79043"]
    Where can I find the 0.5 version?
    [/quote]

    Thomas, we are planning to have the repository publicly available by the end of the day tomorrow. I will post a blog entry here at that time.

    Mark


  4. [quote comment="79060"]Why does this feel like a reimplementation of http://activemq.apache.org/camel/ ?
    What is different?[/quote][/quote]
    Both projects are heavily inspired by "Enterprise Integration Patterns" (http://www.eaipatterns.com), and therefore Spring Integration provides an 'alternative' implementation of the ideas in that book rather than a reimplementation of anything else. As far as the implementation model is concerned, Spring Integration will be focusing on annotations (similar in some respects to Spring 2.5's @Controller and @RequestMapping) in addition to Spring namespace support. At a deeper level than the patterns themselves, we will be providing integration solutions for usage *within* a Spring-based application - building on the core (AOP, dynamic language proxies, etc), but also providing "glue" between the various Spring portfolio projects (Spring Web Services, Spring Batch, etc). That said, we will of course be providing adapters for common external input/output sources, and it's quite possible that Camel is a potential integration point.


  5. Working in EAI, this news is one of most exiting and pleasing Christmas present a Spring lover could get!

    Is very nice to see how various successful Spring related projects are coming together to offer a wider range of possibilities.

    Thanks a lot for all the effort and contributions to open-source comunity!


  6. Mark,

    While it sounds great I've some remarks here:

    1. I'm quite surprised that within adapters we have no WebServices/SOAP - nowadays it's a must and imo it shoul be primary target. Sorry saying this but Burlap/hessian and HttpInvoker are niche playrs compared to WS.

    2. I'm also confused with this move:

    We have camel, service mix (with lightweight components), mule and all those frameworks leverage spring at its core…

    What's rationale behind this?


  7. Artur,

    Spring Web Services already provides comprehensive support for SOAP and plain XML-based Web Services. We will absolutely be providing an adapter that acts as a gateway between the Spring WS endpoints and channels within Spring Integration. This also addresses your 2nd question to some degree in that our goal is to provide the best possible integration with the Spring core and the Spring portfolio. As the designers, implementers, and maintainers of those products, we have a distinct advantage. As this product evolves, I hope that you find it to provide considerable value.

    Mark


  8. Hi Mark

    Any news about the 0.5 version?

    Best Regards
    Thomas


  9. I would love to get my hands on 0.5 as soon as I can. As I mentioned to you (Mark) at TSE, we were looking into Servicemix or Mule, but decided against them because of the complexity associated with a more complete ESB, when we really just want a lightweight message router.

    Hopefully you made it back safely from TSE. We got in before the storm came Saturday evening.

    thanks,
    Brad


  10. Thanks Brad - I did manage to get back even though my original flight had been canceled.

    Thomas (and anyone else wanting to check it out), I apologize for not having the 0.5 snapshot available yet. In order to support anonymous SVN access, some infrastructure needs to be setup, and the planning session for this was canceled while I was managing to adjust my flight schedule in order to make it to a training that I'm conducting this week. It's probably going to be another day or 2 - in the worst case, we may setup a temporary location. I'll keep you posted.

    Mark


  11. Mark

    "Annotations for transformation and routing (e.g. @Router, @Splitter, and @Aggregator) will also be supported"

    Is this related to Map / Reduce algorithm ?


  12. Hi Mark,

    I'm very keen to see what Spring Integration looks like. I'm curious, is the Message interface going to match a more JMS type Message or a more JBI type MessageExchange? The examples seem to suggest the former. I'd probably vote for the latter…


  13. [quote comment="79716"]Mark

    Is this related to Map / Reduce algorithm ?[/quote]

    Hi Mark,

    I think @Router, @Splitter and @Aggregator represent the according enterprise integration patterns, meaning they provide a solution to common tasks in message oriented systems. The Map/Reduce pattern is a paradigm coming from functional programming. So I think although they might seem related, both patterns don't have very much in common.

    Tom


  14. Hi Mark,
    I understand that this is EAI patterns implementatation, not an ESB product, therefore, some of the questions may be off topic:
    1. Mule implements the EAI patterns as well, what differentiates Spring implementations from it.
    2. Any plans to come out with Spring ESB solution competing in ESB space? If this is in works then I would like to know your views on JBI and SCA.
    thanx
    -yogen


  15. Looking forward to seeing this; we're doing a little ESB due diligence right now, so it'd be nice to be able to compare this.


  16. [quote comment="80040"]what differentiates Spring implementations[/quote]
    The differentiators we foresee with Spring Integration will be on 3 levels: consistency in the programming model, reuse of core Spring internals, and seamless integration within the Spring portfolio. Here are a couple quick examples.

    1) consistent programming model: Spring Integration emphasizes non-invasive delegation to strongly typed methods via adapters. When using the XML namespace suppport, this will be very consistent with Spring's 'jms:listener' element (accepting 'ref' and 'method' attributes). When using the annotation-driven approach, it will be consistent with the new Spring 2.5 MVC @Controller/@RequestMapping annotations… in this case @MessageEndpoint and @Router, etc.

    2) core spring internals: Spring Integration will be relying on the exact same abstractions at the core while exposing the same terminology and semantics to the developer. This will apply to many areas - including transaction-management, task execution, and dynamic language support.

    3) the portfolio: Spring Integration will support Spring Security at the level of messaging components (e.g. MessageChannel, MessageEndpoint), will provide gateways for Spring Web Services and Spring MVC/Web Flow, will integrate with job execution in Spring Batch, and so on.

    Additionally, we will be able to respond very quickly to new features and even design new features in collaboration with other products in the portfolio. In summary, we plan to provide the deepest integration with the Spring model. With that as our primary focus, we will not likely provide the same breadth of options as other products initially. However, being consistent with the Spring model also means providing simple extension points and APIs so that other products can integrate in a well-defined manner.

    [quote comment="80040"]views on JBI and SCA.[/quote]
    We are not building the framework upon JBI, because our "component model" is Spring. I should add that there is a lot of hype around the future role of OSGi in this space, and given that we are co-evolving with the Spring Dynamic Modules project, we are particularly well-suited to build upon that. SCA on the other hand is consistent with the concepts of dependency injection, and SpringSource is involved in that initiative, so you can probably expect to see SCA integration at some point.


  17. I always struggle with contrasting the different open source integration products.

    I think you've helped here, because in effect, your appeal is to those who already developing with Spring extensively. From that respect,it makes sense.

    You've made the leap that I suspected was coming - you've gone from wiring a single application to potentially wiring the enterprise. So perhaps an EnterpriseContext class is in order? ;-)


  18. For those of you who have been asking here, I've just posted a follow-up blog (http://blog.interface21.com/main/2007/12/21/spring-integration-samples/) that shows a few more samples and also provides the anonymous SVN checkout information.

    -Mark


  19. Hello Mark,
    How is Spring Integration different from ESBs like ServiceMix,
    Thanks :) Happy new year.


  20. Are milestones and snapshots of the Spring Integration project available in a Maven repository somewhere?


  21. [quote comment="97423"]Are milestones and snapshots of the Spring Integration project available in a Maven repository somewhere?[/quote]

    The milestones are available in the maven repository. See this blog for details: http://blog.springsource.com/main/2007/09/18/maven-artifacts-2

    Snapshots are planned to begin with the upcoming M2 release.

    You can browse the maven repository as well: http://s3browse.com/explore/maven.springframework.org/milestone/org/springframework/integration/

    -Mark


  22. Do you have a diagram showing how all the Integration components can hang together? It would be a very good selling piece, rather than snippets of code as introduction…


  23. @Zeeshan
    We're working on an open-source visualization editor for EIP at http://www.eclipse.org/stp/eid - it's early days yet, but we have plans to make tool pluggable for all sorts of runtimes.


  24. @Zeeshan
    We're working on a visualization editor for EIP over at http://www.eclipse.org/stp/eid - it's early days yet, but we have plans to make the tool totally pluggable so that it can be used with any runtime.

6 trackbacks

Leave a Reply