How to use mappings in routes

Learn how to use mappings in routes.

Prerequisite : Configure mappings


Usage

The Mappings are called by the tnd-absorption component that can only be used as producer :

<to uri="tnd-absorption..." />

URI format

tnd-absorption:mappingName[?options]

or

tnd-absorption://mappingName[?options]

You can also specify the name of the Mapping in the header tnd-absorption-mapping-name, it will be used when the syntax of the URI is tnd-absorption:dynamic. This is particularly useful when grouping absorptions.

URI options

Name Default value Description
wait false Whether or not the call to the Mapping should block until the absorption is complete

Examples

How to define the parameter values of the mapping

Without expressions in mapping

This is the recommended usage

If the Mapping has no expression defined for a parameter then it expects to find its value into a Map in the exchange body.

<route>
   <from uri="direct:payment" />
   <setBody>
       <u:map-create>
           <u:map-entry key="paymentId">
               <header>paymentId</header>
           </u:map-entry>
           <!-- Other key/values -->
       </u:map-create>
   </setBody>
   <to uri="tnd-absorption:absorbPayment" />
</route>

See How to use Camel utilities in routes for explanation of <u:map-create> and <u:setMapValue> that helps managing the map.

With expressions in mapping

This is the legacy behavior

In this case, the way to retrieve the values are defined in the mapping itself in the expressions of the parameters.

Absorb payments without waiting for the absorption to be complete

It's the fastest solution, it doesn't wait until the absorption is complete therefore new payments can be processed and transformed in the meantime.

<route>
   <from uri="direct:payment" />
   <to uri="tnd-absorption:absorbPayment" />
   <!-- At this point a request to this payment will most likely return nothing -->
</route>

Absorb customer with absorption blocking the exchange processing (synchronous)

You won't be able to process new customer in this route until this operation is complete but you will be certain the customer queriable from that point on

<route>
    <from uri="direct:customer" />
    <to uri="tnd-absorption:absorbCustomer?wait=true" />
    <!-- At this point a request to this customer will always return it -->
</route>

Define the name of the mapping at runtime

Sometimes, you want to call on mapping or another depending of a particular state

<route>
    <from uri="absorbPayment"/>
    
    <!-- Select the proper Mapping -->
    <choice>
        <when>
            <simple>${body.isClosed}</simple>
            <setHeader headerName="tnd-absorption-mapping-name">
                <constant>absorbClosedPayment</constant>
            </setHeader>
        </when>
        <otherwise>
            <setHeader headerName="tnd-absorption-mapping-name">
                <constant>absorbOpenPayment</constant>
            </setHeader>
        </otherwise>
    </choice>
    
    <!-- Call the proper Mapping -->
    <to uri="tnd-absorption:dynamic"/>
</route>

 

 

Related Links