Over a million developers have joined DZone.
Platinum Partner

Spring Integration - Payload Storage via Claim-check

· Integration Zone

The Integration Zone is brought to you in partnership with Red Hat. Download the IDC Report: The Business Value of Red Hat Integration Products to learn more about Red hat Integration.

Continuing on the theme of temporary storage for transient messages used within Spring Integration flows, the claim-check model offers configurable storage for message payloads. The advantage in using this Enterprise Integration pattern, compared against header enrichment, is that objects don't have to be packed into the header using a Header Enrichment technique. They can be stored in a local Java Map, an IMDB, cache or anything else that be used to hold data.

Several advantages using this approach are evident. Firstly, performance and efficiency. When using header enrichment, if message payloads need to be managed outside of the JVM that generates the enriched message header, the object will not be available unless it's serialised and transported around the distributed application. This could be costly in terms of performance and transport efficiency. The key factor here is the frequency of remote dispatch and the size of the header object. In specific circumstances the claim-check pattern may offer an advantage here, objects can be serialised and/or transformed into a storage specific format and stored internally in memory or externally in a data store.

Secondly, accessibility. It's conceivable that message payloads undergoing claim-check processing may need to be accessed by third party applications that are unable to receive Spring Integration messages. The claim-check pattern allows this type of processing to take place.

Thirdly, resiliency is offered. A data store can be chosen that guarantees persistence for messages in order that they can be recovered following failure.

The following code details how the claim-check pattern can be used:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"

    <bean id="simpleMessageStore"
    <int:gateway id="claimCheckGateway"

    <int:chain input-channel="claim-check-in-channel"
        <int:claim-check-in message-store="simpleMessageStore"/>


    <int:chain input-channel="processing-channel"
        <int:service-activator expression="new String('different string')"/>

    <int:chain input-channel="claim-check-out-channel">
        <int:claim-check-out message-store="simpleMessageStore"


The gateway used is specified as the following Java class:

package com.l8mdv.sample;

import org.springframework.integration.Message;
import org.springframework.integration.annotation.Gateway;

public interface ClaimCheckGateway {

    public static final String CLAIM_CHECK_ID = "CLAIM_CHECK_ID";

    @Gateway (requestChannel = "claim-check-in-channel")
    public Message<String> send(Message<String> message);

Lastly, this can all be tested by using the following JUnit test case:

package com.l8mdv.sample;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.Message;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static com.l8mdv.sample.ClaimCheckGateway.CLAIM_CHECK_ID;

    locations = {"classpath:META-INF/spring/claim-check.xml"}
public class ClaimCheckIntegrationTest {

    @Autowired ClaimCheckGateway claimCheckGateway;

    public void locatePayloadInHeader() {
        String payload = "Sample test message.";
        Message<String> message = MessageBuilder.withPayload(payload).build();
        Message<String> response = claimCheckGateway.send(message);

        Assert.assertTrue(response.getHeaders().get(CLAIM_CHECK_ID) != null);

The Integration Zone is brought to you in partnership with Red Hat. Download the IDC Report: The Business Value of Red Hat Integration Products to learn more about Red hat Integration.


Published at DZone with permission of Matt Vickery , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}