Red Hat Training

A Red Hat training course is available for JBoss Enterprise SOA Platform

Chapter 10. Routing Output Data

10.1. Output Data Options

Smooks supports a number of different options when it comes to splitting and routing message fragments. The ability to split messages into fragments and route these fragments to different kinds of endpoints (files, JMS, etc.) is a very important capability. Smooks provides this along with the following features:
  • Basic Fragment Splitting: You may need to perform a dumb split on a message, that is, splitting all the order-item fragments in a message and route them to a file. ("Dumb split" means you don't need to perform any type of transformation on the split message fragments before routing, such as merging data from other parts of the message hierarchy before routing. (For example, add customer details info to the order-item fragment before routing)). Basic splitting and routing simply involves defining the XPath of the message fragment to be split out and the defining a routing component (for example, JBoss ESB or Camel) to route that unmodified split message fragment.
  • Complex Fragment Splitting: Basic fragment splitting works for "many use" cases and is what most splitting and routing solutions offer. Smooks extends the basic splitting capabilities by allowing you to perform transformations on the split fragment data before routing is applied. For example, merging in the customer-details order information with each order-item information before performing the routing order-item split fragment routing.
  • In Stream Splitting and Routing (huge message support): Because Smooks can perform routing "in stream" (not batched up for routing after processing the complete message), it is able to accommodate processing of huge message streams that are gigabytes in size.
  • Multiple Splitting and Routing: Conditionally split and route multiple message fragments (different formats XML, EDI, Java etc) to different endpoints in a single filtering pass of the input message stream. For example, routing an OrderItem Java object instance to the HighValueOrdersValidation JMS Queue for order items with a value greater than $1,000 and route all order items (unconditional) as XML/JSON to a HTTP endpoint for logging.

10.2. Routing with Apache Camel

  1. To route message fragments to Apache Camel endpoints, use the camel:route configuration from the http://www.milyn.org/xsd/smooks/camel-1.4.xsd configuration namespace.
  2. Route to a Camel endpoint by specifying the following in your Smooks configuration:
    <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
             xmlns:camel="http://www.milyn.org/xsd/smooks/camel-1.4.xsd">
     
      <!-- Create some bean instances from the input source... -->
      <jb:bean beanId="orderItem"  ... ">
        <!-- etc... See Smooks Java Binding docs -->
      </jb:bean>
     
      <!-- Route bean to camel endpoints... -->
      <camel:route beanId="orderItem">
        <camel:to endpoint="direct:slow" if="orderItem.priority == 'Normal'" />
        <camel:to endpoint="direct:express" if="orderItem.priority == 'High'" />
      </camel:route>
     
    </smooks-resource-list>
    
    
    In the above example, Javabeans is routed from the Smooks BeanContext to the Camel Endpoints. You can also apply templates (such as FreeMarker) to these same beans and route the templating result instead of the beans (such as as XML and CSV).
    routeOnElement.