Skip to content
This repository was archived by the owner on Jul 9, 2022. It is now read-only.

Xml style configuration

olegz edited this page Feb 29, 2012 · 11 revisions

XML to Scala comparison snippets

This page will demonstrate a few code snippets mainly to show diferences and similarities between using XML and Scala when configuring Spring Integration. We'll use OrderProcessing a an example

Scala

val errorFlow = handle.using{m:Message[_] => println("Received ERROR: " + m); "ERROR processing order"}
    
val aggregationFlow = aggregate()

val bikeFlow = 
      handle.using{m:Message[_] => println("Processing bikes order: " + m); m} --> 
      aggregationFlow
   
val orderProcessingFlow =
      filter.using{p:PurchaseOrder => !p.items.isEmpty}.where(exceptionOnRejection = true) -->
      split.using{p:PurchaseOrder => p.items} -->
      Channel.withDispatcher(taskExecutor = Executors.newCachedThreadPool) -->    
      route.using{pi:PurchaseOrderItem => pi.itemType}(
        when("books") then 
            handle.using{m:Message[_] => println("Processing books order: " + m); m} --> 
            aggregationFlow, 
        when("bikes") then 
            bikeFlow    	 
      ) 

XML

XML configuration would look somewhat like this

<int:gateway id="messagingGateway" service-interface="foo.bar.OrderProcessingGateway"
             default-request-channel="startOfFlowChannel"
             error-channel="orderErrorChannel"/>

<int:filter input-channel="startOfFlowChannel" exception-on-rejection="true" 
            output-channel="splitterChannel" expression="!payload.getItems().isEmpty()"/>

<int:splitter input-channel="splitterChannel" expression="payload.getItems()" 
             output-channel="asyncChannel"

<int:channel id="asyncChannel">
   <int:dispatcher executor="executor"/>
</int:channel>

<int:router input-channel="asyncChannel" expression="payload.getItemsType()">
    <int:mapping value="books" channel="booksChannel">
    <int:mapping value="bikes" channel="bikesChannel">
</int:router>

<int:service-activator input-channel="booksChannel" output-channel="aggregationChannel">
    <bean class="foo.bar.BooksService"
</int:service-activator>

<int:service-activator input-channel="bikesChannel" output-channel="aggregationChannel">
    <bean class="foo.bar.BikesService"
</int:service-activator>

<int:aggregator input-channel="aggregationChannel"/>

<!-- error flow -->

<int:service-activator input-channel="orderErrorChannel">
    <bean class="foo.bar.OrderErrorHandler"/>
</int:service-activator>

<task:executor id="executor" . . ./>

Back to Introduction