Blogs

SpringSource Blog

Introducing Spring Integration Scala DSL

Oleg Zhurakousky

Introduction

The Spring Integration team is happy to announce the first milestone release (1.0.0.M1) of the Spring Integration Scala DSL – one of the newest additions to Spring Integration portfolio.

What is the Spring Integration Scala DSL?

The Spring Integration Scala DSL is a Domain Specific Language written in Scala with the goals of:

    • providing a strongly-typed alternative to XML configuration for Spring Integration
    • raising awareness about Spring Integration in Scala community
    • providing first class integration with various Scala frameworks and products such as Akka
    • providing seamless integration with Java where Scala developers can still leverage their existing Java investments

One thing we would like to point out is that the Spring Integration Scala DSL is not itself a new EIP framework. Rather, it's a Scala-based DSL that sits on top of the Java-based Spring Integration framework, and, in the first milestone, the DSL itself still relies heavily on Java types from the Spring Integration API. However, as it progresses through subsequent milestones, the DSL will evolve to become increasingly Scala-esque. We do believe that such close integration with the existing java API provides instant reusability, but we also recognize the benefit of providing Scala wrappers and converters over those types in the future.

Show me

Here is a quick glimpse into the DSL itself:

val messageFlow =
     filter{payload: String => payload == "World"} -->
     transform{ payload: String => "Hello " + payload} -->
     handle{ payload: String => println(payload) }

messageFlow.send("World")

. . . and that is all!

Compare this to its Java/XML equivalent:

XML Configuration (config.xml):

<int:gateway service-interface="foo.bar.MyGateway"
                     default-request-channel="inChannel"/>

<int:filter input-channel="inChannel"
                expression="payload.equals('World')"
	        output-channel="transformingChannel"/>

<int:transformer input-channel="transformingChannel"
                           expression="'Hello ' + payload"
                           output-channel="loggingChannel"/>

<int:service-activator input-channel="loggingChannel"
              expression="T(java.lang.System).out.println(payload)"/>

Java:

public class SpringIntegrationIntro {

    public static void main(String... strings ){
       ApplicationContext context =
         new ClassPathXmlApplicationContext("config.xml");
       MyGateway gateway = context.getBean(MyGateway.class);
       gateway.send("World");
    }

     public static interface MyGateway {
       public void send(String value);
     }
}

The first and perhaps obvious thing you should notice is how much quicker it is to wire something like this using the Scala DSL. But that is not the only benefit. Strong typing and the ability to benefit from other features of a functional language like Scala (e.g., using Scala functions as message processors) are just a few to mention. You can get more information and details from the project's GitHub website which contains a comprehensive Introduction as well as How to get started, DSL Reference and more.

Screen-casts

To help you along the way we have also released 2 screen-casts.

The first screen-cast is a short (~15 min) introduction to Spring Integration Scala DSL which also covers the ideas and motivation behind the project – [Intro-SI-Scala.mov]

Another screen-cast (~10 min) is a visual supplement to How to get Started with Spring Integration Scala DSL which includes a demonstration on how to get started with Eclipse based development environment, as well as IntelliJ IDEA. – [Getting-Started-SI-Scala.mov]

Roadmap

The initial project road-map is available here

Feedback

Let us know what you think by using Spring Integration Forums and Spring Integration Scala DSL JIRA or by posting your comments here.

Similar Posts

Share this Post
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • DZone
  • LinkedIn
  • Slashdot
  • Technorati
  • Twitter
 

10 responses


  1. Hi,

    should be enough with

    val messageFlow =
    filter.using { "World" == } –>
    transform.using { "Hello " _ } –>
    handle.using { println }

    messageFlow.send("World")


  2. This is a great addition to Spring Integration and the Scala community!


  3. @√

    Victor

    Thanks for the feedback and pointers. When i mentioned that we are working on making DSL more Scala-esque, i forgot to mention that it includes us the developers as well ;)

    Will update


  4. This is awesome news!

    IMO, the major advantage of Spring Integration's major competitor Apache Camel is its DSLs (Java, Scala, Groovy) as I have stated in my comparison:
    http://www.kai-waehner.de/blog/2012/01/10/spoilt-for-choice-which-integration-framework-to-use-spring-integration-mule-esb-or-apache-camel/

    The above example has good readability. Besides, strong typing and code completion will help developers a lot.

    Often, Scala DSLs are tough to read. I hope you will create a DSL which is nice and fluent, also in more complex examples. Apache Camel shows that this is really challenging!

    For instance, this is concise and easy to read:
    "direct:a" process(_.in = " says hello") to ("mock:a")

    Though, I do NOT like this one:

    "seda:b" ==> {
    to ("mock:b")
    throttle (3 per (2 seconds)) {
    to ("mock:c")
    }
    }

    Be careful, do not create a DSL which uses too much operator overloading or requires too many nested parentheses…

    Summing up, the Scala DSL is definitely a step into the right direction of Spring Integration!

    Best regards,
    Kai Wähner (Twitter: @KaiWaehner)


  5. @Kai

    Readability is a huge deal and we've been playing with quite a few prototypes to get to this point and you can see from the Introduction – https://github.com/SpringSource/spring-integration-scala/wiki/Introduction that at the core of our approach is to actually make it English readable where EIPs themselves are represented as verbs:

    val messageFlow =
         filter.using{payload: String => payload == "World"} -->
         transform.using { payload: String => "Hello "   payload}
    messageFlow.send("World")
    

    "Send Message, than filter Message, then transform Message . . ."

    So yes we intend to stay on such path and community feedback would be very important in the decision making process.


  6. Fantastic, great to see this in Spring Integration.


  7. Great to see this in SI.

    Will we see a Java-based fluent API in SI soon?

    Camel seems to support one:

    http://camel.apache.org/dsl.html

    …that seems to be in varying degree of use.


  8. Yeah, we are thinking about it. Scala will be first since the language itself is so DSL friendly so its nice to use it and experiment with various ideas, but we'll beging working on Java very soon.


  9. Any plans in near future to release Spring SI DSL project? How soon will it be upgraded to Scala 2.10?


  10. Spring scala DSL integration is going to be very helpful for the future.
    Main benefits of functional language and strong typed characteristics of Scala.

2 trackbacks

Leave a Reply