DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Introducing Stalactite ORM
  • Spring Boot Microservices + Apache Camel: A Hello World Example
  • Incorporating Fault-Tolerance Into Your Microservice Architecture
  • How Spring and Hibernate Simplify Web and Database Management

Trending

  • Prioritizing Cloud Security Risks: A Developer's Guide to Tackling Security Debt
  • Optimizing Serverless Computing with AWS Lambda Layers and CloudFormation
  • Next Evolution in Integration: Architecting With Intent Using Model Context Protocol
  • ITBench, Part 1: Next-Gen Benchmarking for IT Automation Evaluation
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Spring Integration - Payload Storage via Claim-check

Spring Integration - Payload Storage via Claim-check

By 
Matt Vickery user avatar
Matt Vickery
·
May. 04, 12 · Interview
Likes (0)
Comment
Save
Tweet
Share
13.8K Views

Join the DZone community and get the full member experience.

Join For Free
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"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:int="http://www.springframework.org/schema/integration"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/integration
       http://www.springframework.org/schema/integration/spring-integration-2.1.xsd">

    <bean id="simpleMessageStore"
          class="org.springframework.integration.store.SimpleMessageStore"/>
    <int:gateway id="claimCheckGateway"
                 service-interface="com.l8mdv.sample.ClaimCheckGateway"/>

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

                name="#{T(com.l8mdv.sample.ClaimCheckGateway).CLAIM_CHECK_ID}"
                expression="payload"/>
        </int:header-enricher>
    </int:chain>

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

    <int:chain input-channel="claim-check-out-channel">
        <int:transformer
                expression="headers.get('#{T(com.l8mdv.sample.ClaimCheckGateway)
                .CLAIM_CHECK_ID}')"/>
        <int:claim-check-out message-store="simpleMessageStore"
                             remove-message="true"/>
    </int:chain>

</beans>


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;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(
    locations = {"classpath:META-INF/spring/claim-check.xml"}
)
public class ClaimCheckIntegrationTest {

    @Autowired ClaimCheckGateway claimCheckGateway;

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

        Assert.assertTrue(response.getPayload().equals(payload));
        Assert.assertTrue(response.getHeaders().get(CLAIM_CHECK_ID) != null);
    }
}
Spring Integration Enterprise integration Payload (computing) Spring Framework

Published at DZone with permission of Matt Vickery, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Introducing Stalactite ORM
  • Spring Boot Microservices + Apache Camel: A Hello World Example
  • Incorporating Fault-Tolerance Into Your Microservice Architecture
  • How Spring and Hibernate Simplify Web and Database Management

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!