Claim Check - 6.3

Talend ESB Mediation Developer Guide

EnrichVersion
6.3
EnrichProdName
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
task
Design and Development
EnrichPlatform
Talend ESB

The Claim Check from the EIP patterns allows you to replace message content with a claim check (a unique key), which can be used to retrieve the message content at a later time. The message content is stored temporarily in a persistent store like a database or file system. This pattern is very useful when message content is very large (thus it would be expensive to send around) and not all components require all information.

It can also be useful in situations where you cannot trust the information with an outside party; in this case, you can use the Claim Check to hide the sensitive portions of data.

In the below example we'll replace a message body with a claim check, and restore the body at a later step.

Using the Fluent Builders

from("direct:start").to("bean:checkLuggage", "mock:testCheckpoint", "
   bean:dataEnricher", "mock:result");

Using the Spring XML Extensions

<route>
   <from uri="direct:start"/>
   <pipeline>
      <to uri="bean:checkLuggage"/>
      <to uri="mock:testCheckpoint"/>
      <to uri="bean:dataEnricher"/>
      <to uri="mock:result"/>
   </pipeline>
</route>

The example route is pretty simple - it's a Pipeline. In a real application you would have some other steps where the mock:testCheckpoint endpoint is in the example.

The message is first sent to the checkLuggage bean which looks like

public static final class CheckLuggageBean {        
    public void checkLuggage(Exchange exchange, @Body String body, 
        @XPath("/order/@custId") String custId) {   
        // store the message body into the data store, 
        // using the custId as the claim check
        dataStore.put(custId, body);
        // add the claim check as a header
        exchange.getIn().setHeader("claimCheck", custId);
        // remove the body from the message
        exchange.getIn().setBody(null);
    }
}    

This bean stores the message body into the data store, using the custId as the claim check. In this example, we're just using a HashMap to store the message body; in a real application you would use a database or file system, etc. Next the claim check is added as a message header for use later. Finally we remove the body from the message and pass it down the pipeline.

The next step in the pipeline is the mock:testCheckpoint endpoint which is just used to check that the message body is removed, claim check added, etc.

To add the message body back into the message, we use the dataEnricher bean which looks like

public static final class DataEnricherBean {
    public void addDataBackIn(Exchange exchange, @Header("claimCheck") 
        String claimCheck) { 
        // query the data store using the claim check as the key and  
        // add the data back into the message body
        exchange.getIn().setBody(dataStore.get(claimCheck));
        // remove the message data from the data store
        dataStore.remove(claimCheck);
        // remove the claim check header
        exchange.getIn().removeHeader("claimCheck");
    }
}    

This bean queries the data store using the claim check as the key and then adds the data back into the message. The message body is then removed from the data store and finally the claim check is removed. Now the message is back to what we started with!

For full details, check the example source here:

camel-core/src/test/java/org/apache/camel/processor/ClaimCheckTest.java