Secondly, the same action can be performed using a Service Activator:
Here's a claim-check retrieval - notice the configuration option that triggers the Spring Integration framework to remove the object from the message store once it has been retrieved. If a message requires access several times in a flow, the last claim-check-out can be configured in this way in order to clean-up.
Several interesting points arise:
- As can be seen here, it's advisable to reference constants for header key values rather than have the header name appearing as literals in several places throughout the code and configuration. On first sight the SpEL expression language may seem hard to fathom but it's worth investing the effort in order to understand it.
- Don't forget that when header objects are moved back into Spring Integration payloads, the object remains in the Spring Integration message header. It may be worth clearing the header value away as part of transformation from the header back to the payload in order to maintain a cleaner and clearer Spring Integration message.
- The intent should be clear from the configuration, what looks better a Service Activator expression or a Transformer? In my view the transformer conveys a slightly more accurate intent.
- Consider using a claim-check integration pattern instead of loading the header. The Spring Integration claim-check uses a referenced message store (and provides a default implementation) that can be house-cleaned automatically by the framework.