Pregunta

I'm reading about the Claim Check pattern in Spring Integration.

When using this pattern, it sounds as though the entire payload is placed in the message store and the resulting payload is only the claim check id.

Does Spring provide a simple way to store the payload in the message store while at the same time retaining specific parts of the payload? Would you need to use a header enricher first and store the properties you want access to in the header?

For example, say my payload is a simple XML document:

<payload>
    <cc>1234432156788765</cc>
    <or>5799</or>
</payload>

I want to claim check this payload but still retain access to the payload.or element. How could this be done using current Spring Integration components?

¿Fue útil?

Solución

The main purpose of Claim Check is to store the message and not have to worry about its size as the message might travel though several external systems. It can also be restored after system failure.

The best example from the real world is flight luggage. During transfers, you have in hand only the receipt and get the luggage at the end.

To achieve your goal I suggest you use <enricher>:

<int:enricher request-channel="claimCheckInChannel">
   <int:header name="claimCheck" expression="payload"/>
</int:enricher>

<claim-check-in input-channel="claimCheckInChannel" message-store="messageStore"/>

With that you don't lose the original payload and have the Claim Check id in the headers.

Note: Claim Check stores the entire message with headers, not only the payload. The relevant code is from org.springframework.integration.transformer.ClaimCheckInTransformer:

@Override
protected Object doTransform(Message<?> message) throws Exception {
    Assert.notNull(message, "message must not be null");
    Object payload = message.getPayload();
    Assert.notNull(payload, "payload must not be null");
    Message<?> storedMessage = this.messageStore.addMessage(message);
    MessageBuilder<?> responseBuilder = MessageBuilder.withPayload(storedMessage.getHeaders().getId());
    // headers on the 'current' message take precedence
    responseBuilder.copyHeaders(message.getHeaders());
    return responseBuilder.build();
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top